Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomasbjerre/violation-comments-lib
Library for commenting things with violations from static code analysis.
https://github.com/tomasbjerre/violation-comments-lib
static-code-analysis
Last synced: 3 months ago
JSON representation
Library for commenting things with violations from static code analysis.
- Host: GitHub
- URL: https://github.com/tomasbjerre/violation-comments-lib
- Owner: tomasbjerre
- License: apache-2.0
- Created: 2016-03-03T20:39:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-11-09T15:50:04.000Z (3 months ago)
- Last Synced: 2024-11-09T16:34:11.371Z (3 months ago)
- Topics: static-code-analysis
- Language: Java
- Size: 484 KB
- Stars: 12
- Watchers: 3
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Violation Comments Lib
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.bjurr.violations/violation-comments-lib/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.bjurr.violations/violation-comments-lib)
This is a library that helps working with comments from static code analysis.
It supports the same formats as [Violations Lib](https://github.com/tomasbjerre/violations-lib).
It is used by these libraries:
* [Violation Comments to GitHub Lib](https://github.com/tomasbjerre/violation-comments-to-github-lib).
* [Violation Comments to GitLab Lib](https://github.com/tomasbjerre/violation-comments-to-gitlab-lib).
* [Violation Comments to Bitbucket Server Lib](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib).
* [Violation Comments to Bitbucket Cloud Lib](https://github.com/tomasbjerre/violation-comments-to-bitbucket-cloud-lib)## 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:
* `violation` that is an instance of [Violation](src/main/java/se/bjurr/violations/comments/lib/model/ViolationData.java).
* `changedFile` that is an instance of [ChangedFile](src/main/java/se/bjurr/violations/comments/lib/model/ChangedFile.java).The templating language is [Handlebars](https://github.com/jknack/handlebars.java) and may look like:
```hbs
**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:```hbs
{{{violation.message}}}
```When using command line tools you may have problems with the ` (accent) character. You can do:
```bash
...
-comment-template "
message:
\\\`\\\`\\\`
{{{violation.message}}}
\\\`\\\`\\\`
"
```And it will surround the `message` with triple ```.
### Helpers
The Handlebars library comes with [helper methods](https://github.com/jknack/handlebars.java/tree/master/handlebars/src/main/java/com/github/jknack/handlebars/helper), these are registered:
* `ConditionalHelpers`
* `IfHelper`
* `StringHelpers`
* `UnlessHelper`