Skip to content

Repository files navigation

Violation Comments Lib

Maven Central

This is a library that helps working with comments from static code analysis.

It supports the same formats as Violations Lib.

It is used by these libraries:

Template

It uses a template to render each violation comment. There is a default that can be replaced with a custom template.

The context available when the template is rendered is:

The templating language is Handlebars and may look like:

**Reporter**: {{violation.reporter}}{{#violation.rule}}

**Rule**: {{violation.rule}}{{/violation.rule}}
**Severity**: {{violation.severity}}
**File**: {{changedFile.filename}} L{{violation.startLine}}{{#violation.source}}

**Source**: {{violation.source}}{{/violation.source}}

{{violation.message}}

You can avoid escaping (replaces new lines with 
) by using triple { like this:

{{{violation.message}}}

When using command line tools you may have problems with the ` (accent) character. You can do:

...
-comment-template "
message: 
\\\`\\\`\\\`
{{{violation.message}}}
\\\`\\\`\\\`
"

And it will surround the message with triple ```.

Helpers

The Handlebars library comes with helper methods, these are registered:

  • ConditionalHelpers
  • IfHelper
  • StringHelpers
  • UnlessHelper

Summary comment

A CommentsProvider can opt in to a separate summary comment, distinct from the per-violation comments and from the single accumulated comment made by shouldCreateCommentWithAllSingleFileComments. It is off by default, so existing implementations are unaffected; enable it by overriding shouldCreateSummaryComment() to return true.

The context available when the summary template is rendered is:

  • summary that is an instance of SummaryData, exposing violationsCount, filesCount, violations, perSeverity (list of severity/count) and perReporter (list of reporter/count).

The default template looks like:

**Summary**: {{summary.violationsCount}} violation(s) found in {{summary.filesCount}} file(s).
{{#summary.perSeverity}}
- **{{severity}}**: {{count}}
{{/summary.perSeverity}}

It can be replaced by overriding findSummaryCommentTemplate(), the same way the per-violation template is replaced with findCommentTemplate().

About

Library for commenting things with violations from static code analysis.

Topics

Resources

Stars

14 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages