Report static code analysis to GitLab.



Report static code analysis to GitLab. It uses the Violations Lib.
| Version | Java Version |
| ------------------| ------------ |
| version < 1.33.0 | 8 |
| 1.33.0 - 1.35.1 | 11 |
| 1.36.0 <= version | 17 |
The runnable can be found in NPM.
Run it with:
``shell`
npx violation-comments-to-gitlab-command-line \
-at K2RS-JdV6Rh3sQJmMQgV \
-pi tomas.bjerre85/violations-test \
-mr-iid 1 \
-v "CHECKSTYLE" "." ".*checkstyle/main\.xml$" "Checkstyle" \
-v "JSHINT" "." ".*jshint/report\.xml$" "JSHint"
An alternative to this tools is transforming the reports to CodeClimate use that to report to GitLab, see README in violations-command-line.
You must perform the merge before build. If you don't perform the merge, the reported violations will refer to other lines then those in the pull request. The merge can be done with a shell script like this.
`
echo ---
echo --- Merging from $FROM in $FROMREPO to $TO in $TOREPO
echo ---
git clone $TOREPO
cd *
git reset --hard $TO
git status
git remote add from $FROMREPO
git fetch from
git merge $FROM
git --no-pager log --max-count=10 --graph --abbrev-commit
Your build command here!
`
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`
-api-token, -at
-api-token-private
Default: true
-comment-only-changed-content, -cocc
Default: true
-comment-only-changed-content-context, -coccc
Default: 0
-comment-only-changed-files, -cocf
files should be commented.
False if all findings should
be commented.
Default: true
-comment-template
com/tomasbjerre/violation-comments-lib
Default:
-create-comment-with-all-single-file-comments, -
ccwasfc
-create-single-file-comments, -csfc
Default: true
-gitlab-url, -gu
Default: https://gitlab.com/
-h, --help
Default: If no specific parameter is given the whole usage text is given
-ignore-certificate-errors
Default: true
-keep-old-comments
Default: false
-max-number-of-comments, -mnoc
Default: 2,147,483,647
-mr-iid
-project-id, -pi
the number. Like 'tomas.
bjerre85/violations-test' or '2732496'
Default:
-proxy-password
Default:
-proxy-server
Default:
-proxy-user
Default:
-severity, -s
to report.
Default: INFO
-should-set-wip
Default: false
-show-debug-info Please run your
command with this parameter
and supply output when
reporting bugs.
Default: disabled
--violations, -v
for.
PARSER is one of:
ANDROIDLINT, CHECKSTYLE, CODENARC,
CLANG, CPD, CPPCHECK,
CPPLINT, CSSLINT, FINDBUGS,
FLAKE8, FXCOP, GENDARME, IAR,
JCREPORT, JSHINT, LINT,
KLOCWORK, KOTLINMAVEN,
KOTLINGRADLE, MSCPP, MYPY, GOLINT,
GOOGLEERRORPRONE, PERLCRITIC, PITEST,
PMD, PYDOCSTYLE, PYLINT,
RESHARPER, SBTSCALAC, SIMIAN,
SONAR, STYLECOP, XMLLINT,
YAMLLINT, ZPTLINT, DOCFX, PCLINT
Example: -v "JSHINT"
"." ".*/jshint.xml$"
"JSHint" [Supports Multiple occurrences]
Default: Empty list
Checkout the Violations Lib for more documentation.
The -comment-template` parameter can be used to fix encoding problems, or just adjust what is being commented. See README in violation-comments-lib.