CLI find report files from static code analysis, present and optionally fail.
npm install violations-command-line



This is a command line tool that will find report files from static code analysis, present and optionally fail the command. It uses the Violations Lib.
- The runnable can be found in Maven Central
- or NPM.
- The Docker image can be found in Dockerhub
- Can used like docker run --mount src="$(pwd)",target=/home/violations-command-line,type=bind tomasbjerre/violations-command-line:a.b.c -v "FINDBUGS" src/test/resources/findbugs/ ".*main\.xml$" "Spotbugs".
- Or open a shell to have a look docker run --rm -it --entrypoint sh tomasbjerre/violations-command-line:a.b.c
| Version | Java Version |
| ------------------| ------------ |
| version < 2.0.0 | 8 |
| 2.0.0 - 3.2.1 | 11 |
| 3.2.2 <= version | 17 |
Run it with:
``bash`
npx violations-command-line -s ERROR -mv 0 \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle" \
-v "JSLINT" "." ".*jshint/report\.xml$" "JSHint"
It can parse results from static code analysis and:
- Report violations in the build log.
- Export to a normalized JSON format.
`bash`
npx violations-command-line -vf violations-report.json \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle"
- Export to CodeClimate JSON.
`bash`
npx violations-command-line -cc code-climate-report.json \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle"
- Export to Sarif JSON.
`bash`
npx violations-command-line -sa sarif-report.json \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle"
- Optionally fail the build depending on violations found.
A snippet of the output may look like this:
` ║ ║
...
se/bjurr/violations/lib/example/OtherClass.java
╔══════════╤════════════╤══════════╤══════╤════════════════════════════════════════════════════╗
║ Reporter │ Rule │ Severity │ Line │ Message ║
╠══════════╪════════════╪══════════╪══════╪════════════════════════════════════════════════════╣
║ Findbugs │ MS_SHOULD_ │ INFO │ 7 │ Field isn't final but should be ║
║ │ BE_FINAL │ │ │ ║
║ │ │ │ │ ║
║ │ │ │ │
║ │ │ │ │ This static field public but not final, and ║
║ │ │ │ │ could be changed by malicious code or ║
║ │ │ │ │ by accident from another package. ║
║ │ │ │ │ The field could be made final to avoid ║
║ │ │ │ │ this vulnerability.
╟──────────┼────────────┼──────────┼──────┼────────────────────────────────────────────────────╢
║ Findbugs │ NM_FIELD_N │ INFO │ 6 │ Field names should start with a lower case letter ║
║ │ AMING_CONV │ │ │ ║
║ │ ENTION │ │ │ ║
║ │ │ │ │
║ │ │ │ │ Names of fields that are not final should be in mi ║
║ │ │ │ │ xed case with a lowercase first letter and the fir ║
║ │ │ │ │ st letters of subsequent words capitalized. ║
║ │ │ │ │
╚══════════╧════════════╧══════════╧══════╧════════════════════════════════════════════════════╝
Summary of se/bjurr/violations/lib/example/OtherClass.java
╔══════════╤══════╤══════╤═══════╤═══════╗
║ Reporter │ INFO │ WARN │ ERROR │ Total ║
╠══════════╪══════╪══════╪═══════╪═══════╣
║ Findbugs │ 2 │ 0 │ 0 │ 2 ║
╟──────────┼──────┼──────┼───────┼───────╢
║ │ 2 │ 0 │ 0 │ 2 ║
╚══════════╧══════╧══════╧═══════╧═══════╝
Summary
╔════════════╤══════╤══════╤═══════╤═══════╗
║ Reporter │ INFO │ WARN │ ERROR │ Total ║
╠════════════╪══════╪══════╪═══════╪═══════╣
║ Checkstyle │ 4 │ 1 │ 1 │ 6 ║
╟────────────┼──────┼──────┼───────┼───────╢
║ Findbugs │ 2 │ 2 │ 5 │ 9 ║
╟────────────┼──────┼──────┼───────┼───────╢
║ │ 6 │ 3 │ 6 │ 15 ║
╚════════════╧══════╧══════╧═══════╧═══════╝
`
GitHub is supported via SARIF. This tool can export SARIF format and it can be uploaded to Github to get feedback in pull-requests.
`yml
name: My workflow
on: [workflow_call, push, pull_request]
jobs:
build:
permissions:
security-events: write
actions: read
contents: read
steps:
- name: Build
run: |
your-build-command-here
- name: Transorm static code analysis to SARIF
if: success() || failure()
run: |
npx violations-command-line -sarif sarif-report.json \
-v "FINDBUGS" "." ".*spotbugs/main\.xml$" "Spotbugs" \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle" \
-v "PMD" "." ".*pmd/main\.xml$" "PMD" \
-v "JUNIT" "." ".test/TEST-.\.xml$" "JUNIT"
- uses: github/codeql-action/upload-sarif@v3
if: success() || failure()
with:
sarif_file: sarif-report.json
category: violations-lib
`
GitLab is supported via CodeClimate. This tool can export CodeClimate format and it can be uploaded to GitLab to get feedback in pull-requests.
If you export CodeClimate like this:
`sh`
npx violations-command-line -cc code-climate-report.json \
-v "FINDBUGS" "." ".*spotbugs/main\.xml$" "Spotbugs" \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle" \
-v "PMD" "." ".*pmd/main\.xml$" "PMD" \
-v "JUNIT" "." ".test/TEST-.\.xml$" "JUNIT"
You can upload it like this:
`yml`
artifacts:
paths:
- code-climate-report.json
reports:
codequality: code-climate-report.json
Example of supported reports are available here.
A number of parsers have been implemented. Some parsers can parse output from several reporters.
| Reporter | Parser | Notes
| --- | --- | ---
| _ARM-GCC_ | CLANG | ANDROIDLINT
| _AndroidLint_ | | ANSIBLELATER
| _Ansible-Later_ | | With json formatFLAKE8
| _AnsibleLint_ | | With -pCLANG
| _Bandit_ | | With bandit -r examples/ -f custom -o bandit.out --msg-template "{abspath}:{line}: {severity}: {test_id}: {msg}"CLANG
| _CLang_ | | CPD
| _CPD_ | | CPPCHECK
| _CPPCheck_ | | With cppcheck test.cpp --output-file=cppcheck.xml --xmlCPPLINT
| _CPPLint_ | | CSSLINT
| _CSSLint_ | | CHECKSTYLE
| _Checkstyle_ | | JUNIT
| _CloudFormation Linter_ | | cfn-lint . -f junit --output-file report-junit.xmlCODECLIMATE
| _CodeClimate_ | | CODENARC
| _CodeNarc_ | | COVERITY
| _Coverity_ | | MACHINE
| _Dart_ | | With dart analyze --format=machineSARIF
| _Dependency Check_ | | Using --format SARIFCHECKSTYLE
| _Detekt_ | | With --output-format xml.DOCFX
| _DocFX_ | | CLANG
| _Doxygen_ | | CLANG
| _ERB_ | | With erb -P -x -T '-' "${it}" \| ruby -c 2>&1 >/dev/null \| grep '^-' \| sed -E 's/^-([a-zA-Z0-9:]+)/${filename}\1 ERROR:/p' > erbfiles.out.CHECKSTYLE
| _ESLint_ | | With format: 'checkstyle'.FINDBUGS
| _Findbugs_ | | FLAKE8
| _Flake8_ | | FXCOP
| _FxCop_ | | CLANG
| _GCC_ | | GHS
| _GHS_ | | GENDARME
| _Gendarme_ | | GENERIC
| [_Generic reporter_]() | | Will create one single violation with all the content as message.GOLINT
| _GoLint_ | | GOLINT
| _GoVet_ | | Same format as GoLint.CHECKSTYLE
| _GolangCI-Lint_ | | With --out-format=checkstyle.GOOGLEERRORPRONE
| _GoogleErrorProne_ | | CHECKSTYLE
| _HadoLint_ | | With -f checkstyleIAR
| _IAR_ | | With --no_wrap_diagnosticsPMD
| _Infer_ | | Facebook Infer. With --pmd-xml.JACOCO
| _JACOCO_ | | JCREPORT
| _JCReport_ | | JSLINT
| _JSHint_ | | With --reporter=jslint or the CHECKSTYLE parser with --reporter=checkstyleJUNIT
| _JUnit_ | | It only contains the failures.CHECKSTYLE
| _KTLint_ | | KLOCWORK
| _Klocwork_ | | KOTLINGRADLE
| _KotlinGradle_ | | Output from Kotlin Gradle Plugin.KOTLINMAVEN
| _KotlinMaven_ | | Output from Kotlin Maven Plugin.LINT
| [_Lint_]() | | A common XML format, used by different linters.MSBULDLOG
| _MSBuildLog_ | | With -fileLogger use .*msbuild\\.log$ as pattern or -fl -flp:logfile=MyProjectOutput.log;verbosity=diagnostic for a custom output filenameMSCPP
| _MSCpp_ | | FLAKE8
| _Mccabe_ | | MYPY
| _MyPy_ | | GOOGLEERRORPRONE
| _NullAway_ | | Same format as Google Error Prone.PCLINT
| _PCLint_ | | PC-Lint using the same output format as the Jenkins warnings plugin, _details here_CHECKSTYLE
| _PHPCS_ | | With phpcs api.php --report=checkstyle.PMD
| _PHPPMD_ | | With phpmd api.php xml ruleset.xml.PMD
| _PMD_ | | FLAKE8
| _Pep8_ | | PERLCRITIC
| _PerlCritic_ | | PITEST
| _PiTest_ | | PROTOLINT
| _ProtoLint_ | | CLANG
| _Puppet-Lint_ | | With -log-format %{fullpath}:%{line}:%{column}: %{kind}: %{message}PYDOCSTYLE
| _PyDocStyle_ | | FLAKE8
| _PyFlakes_ | | PYLINT
| _PyLint_ | | With pylint --output-format=parseable.RESHARPER
| _ReSharper_ | | CLANG
| _RubyCop_ | | With rubycop -f clang file.rbSARIF
| _SARIF_ | | v2.x. Microsoft Visual C# can generate it with ErrorLog="BuildErrors.sarif,version=2".SBTSCALAC
| _SbtScalac_ | | CHECKSTYLE
| _Scalastyle_ | | SEMGREP
| _Semgrep_ | | With --json.SIMIAN
| _Simian_ | | SONAR
| _Sonar_ | | With mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json. Removed in 7.7, see SONAR-11670 but can be retrieved with: curl --silent 'http://sonar-server/api/issues/search?componentKeys=unique-key&resolved=false' \| jq -f sonar-report-builder.jq > sonar-report.json.FINDBUGS
| _Spotbugs_ | | STYLECOP
| _StyleCop_ | | CHECKSTYLE
| _SwiftLint_ | | With --reporter checkstyle.CHECKSTYLE
| _TSLint_ | | With -t checkstyleVALGRIND
| _Valgrind_ | | With --xml=yes.XMLLINT
| _XMLLint_ | | XUNIT
| _XUnit_ | | It only contains the failures.YAMLLINT
| _YAMLLint_ | | With -f parsableZPTLINT
| _ZPTLint_ | |
52 parsers and 79 reporters.
Missing a format? Open an issue here!
`shell
Available parsers are:
ANDROIDLINT, ANSIBLELATER, CHECKSTYLE, CODENARC, CLANG, COVERITY, CPD, CPPCHECK, CPPLINT, CSSLINT, GENERIC, GHS, FINDBUGS, FLAKE8, MACHINE, FXCOP, GENDARME, IAR, JACOCO, JCREPORT, JSLINT, JUNIT, LINT, KLOCWORK, KOTLINMAVEN, KOTLINGRADLE, MSCPP, MSBULDLOG, MYPY, GOLINT, GOOGLEERRORPRONE, PERLCRITIC, PITEST, PMD, PROTOLINT, PYDOCSTYLE, PYLINT, RESHARPER, SARIF, SBTSCALAC, SEMGREP, SIMIAN, SONAR, STYLECOP, XMLLINT, YAMLLINT, ZPTLINT, DOCFX, PCLINT, CODECLIMATE, XUNIT, VALGRIND
Usage: violations-command-line [-dpv] [--help] [-pv] [-show-debug-info]
[-show-json-config] [-cc=
[-cf=
[-df=
[-dmv=
[-ds=
[-gr=
[-jmlc=
[-mlcw=
[-mmcw=
[-mrcw=
[-mrucw=
[-mscw=
[-mv=
[-ss=
[-v=
-cc, -code-climate=
Create a CodeClimate file with all the violations.
-cf, -config-file=
Will read config from given file. Can also be
configured with environment variable
VIOLATIONS_CONFIG. Format is what you get from
-show-json-config.
-ddl, -diff-detail-level=
VERBOSE, COMPACT, PER_FILE_COMPACT
-df, -diff-from=
Can be empty (ignored), Git-commit or any
Git-reference
-dl, -detail-level=
Verbosity VERBOSE, COMPACT, PER_FILE_COMPACT
-dmv, -diff-max-violations=
Will fail the build if total number of found
violations is higher
-dpv, -diff-print-violations
Will print violations found in diff
-ds, -diff-severity=
INFO, WARN, ERROR
-dt, -diff-to=
Can be empty (ignored), Git-commit or any
Git-reference
-gr, -git-repo=
Where to look for Git.
--help display this help and exit
-jmc, -jacoco-min-coverage=
Minimum coverage in Jacoco that will generate a
violation.
-jmlc, -jacoco-min-line-count=
Minimum line count in Jacoco that will generate a
violation.
-mlcw, -max-line-column-width=
0 means no limit
-mmcw, -max-message-column-width=
0 means no limit
-mrcw, -max-reporter-column-width=
0 means no limit
-mrucw, -max-rule-column-width=
0 means no limit
-mscw, -max-severity-column-width=
0 means no limit
-mv, -max-violations=
Will fail the build if total number of found
violations is higher.
-pv, -print-violations
Will print violations found
-s, -severity=
Minimum severity level to report. INFO, WARN, ERROR
-show-debug-info Please run your command with this parameter and
supply output when reporting bugs.
-show-json-config Will print the given config as JSON.
-ss, -sarif=
Create a Sarif file with all the violations.
-v, --violations=
Format:
Example: -v "JSLINT" "." ".*/jshint.xml$" "JSHint"
-vf, -violations-file=
Create a JSON file with all the violations.
``
Checkout the Violations Lib for more documentation.