Skip to content

๐Ÿ”Ž Super_linter

GitLab Linter Quality

Objective

This job uses the github super-linter which is a Simple combination of various linters to help validate the quality of your source code. This job permit to fully integrate it in Gitlab (super-linter is originally made for Github Actions).

More than 36 languages are supported :

Language Linter
Ansible ansible-lint
Azure Resource Manager (ARM) arm-ttk
AWS CloudFormation templates cfn-lint
C# dotnet-format
CSS stylelint
Clojure clj-kondo
CoffeeScript coffeelint
Dart dartanalyzer
Dockerfile dockerfilelint / hadolint
EDITORCONFIG editorconfig-checker
ENV dotenv-linter
Golang golangci-lint
Groovy npm-groovy-lint
HTML HTMLHint
Java checkstyle
JavaScript eslint / standard js
JSON jsonlint
Kubeval kubeval
Kotlin ktlint
LaTeX ChkTex
Lua luacheck
Markdown markdownlint
OpenAPI spectral
Perl perlcritic
PHP PHP built-in linter / PHP CodeSniffer / PHPStan / Psalm
PowerShell PSScriptAnalyzer
Protocol Buffers protolint
Python3 pylint / flake8 / black
R lintr
Raku Raku
Ruby RuboCop
Shell Shellcheck / [executable bit check] / shfmt
Snakemake snakefmt / snakemake --lint
SQL sql-lint
Tekton tekton-lint
Terraform tflint / terrascan
Terragrunt terragrunt
TypeScript eslint / standard js
XML LibXML
YAML YamlLint

How to use it

  1. The job can be run "out of the box". If you need to personalize its behavior, check the variables section
  2. Add this job URL inside the include list of your .gitlab-ci.yml file (see the quick setup). You can specify a fixed version instead of latest.
      - remote: 'https://jobs.r2devops.io/latest/super_linter.yml'
    
  3. If you need to customize the job (stage, variables, ...) ๐Ÿ‘‰ check the jobs customization
  4. Well done, your job is ready to work ! ๐Ÿ˜€

Job details

  • Job name: super_linter
  • Docker image: github/super-linter
  • Default stage: static_tests
  • When: always

Variables

Info

This section describes the most significant variables from this full list.

This job can be used without configuration. By default, it will detect files in your repository and run relevant linter on them. You can also use variables to customize its behavior.

General configuration

Name Description Default
ACTIONS_RUNNER_DEBUG Flag to enable additional information about the linter, versions, and additional output. false
DISABLE_ERRORS Flag to have the linter complete with exit code 0 even if errors were detected. false
FILTER_REGEX_EXCLUDE Regular expression defining which files will be excluded from linting (ex: .*src/test.*) none
FILTER_REGEX_INCLUDE Regular expression defining which files will be processed by linters (ex: .*src/.*) all
LOG_LEVEL How much output the script will generate to the console. One of VERBOSE, DEBUG or TRACE. VERBOSE
MULTI_STATUS A status API is made for each language that is linted to make visual parsing easier. true
REPORT_SUITE_TEST_NAME Name of test suite inside test report super_linter

Linters configuration

Name Description Default
ANSIBLE_DIRECTORY Flag to set the root directory for Ansible file location(s), relative to DEFAULT_WORKSPACE. /ansible
CSS_FILE_NAME Filename for Stylelint configuration (ex: .stylelintrc.yml, .stylelintrc.yaml) .stylelintrc.json
DOCKERFILE_HADOLINT_FILE_NAME Filename for hadolint configuration (ex: .hadolintlintrc.yaml) .hadolint.yml
ERROR_ON_MISSING_EXEC_BIT If set to false, the bash-exec linter will report a warning if a shell script is not executable. If set to true, the bash-exec linter will report an arror instead. false
JAVASCRIPT_ES_CONFIG_FILE Filename for eslint configuration (ex: .eslintrc.yml, .eslintrc.json) .eslintrc.yml
LINTER_RULES_PATH Directory for all linter configuration rules. .linters
MARKDOWN_CONFIG_FILE Filename for Markdownlint configuration (ex: .markdown-lint.yml, .markdownlint.json, .markdownlint.yaml) .markdown-lint.yml
PYTHON_PYLINT_CONFIG_FILE Filename for pylint configuration (ex: .python-lint, .pylintrc) .python-lint
PYTHON_FLAKE8_CONFIG_FILE Filename for flake8 configuration (ex: .flake8, tox.ini) .flake8
PYTHON_BLACK_CONFIG_FILE Filename for black configuration (ex: .isort.cfg, pyproject.toml) .python-black
RUBY_CONFIG_FILE Filename for rubocop configuration (ex: .ruby-lint.yml, .rubocop.yml) .ruby-lint.yml
SNAKEMAKE_SNAKEFMT_CONFIG_FILE Filename for Snakemake configuration (ex: pyproject.toml, .snakefmt.toml) .snakefmt.toml
TYPESCRIPT_ES_CONFIG_FILE Filename for eslint configuration (ex: .eslintrc.yml, .eslintrc.json) .eslintrc.yml
YAML_CONFIG_FILE Filename for Yamllint configuration (ex: .yaml-lint.yml, .yamllint.yml) .yaml-lint.yml

Warning

Please be aware that any config file specified is relative to $LINTER_RULES_PATH, so you have to put all your templating under the path specified. If you are curious to know what are the default templates files for your linters, they are all available in the TEMPLATES folder

Enable or disable linters

Note about VALIDATE_[LANGUAGE] variables from super-linter README

Note: All the VALIDATE_[LANGUAGE] variables behave in a very specific way:

  • If none of them are passed, then they all default to true.
  • If any one of the variables are set to true, we default to leaving any unset variable to false (only validate those languages).
  • If any one of the variables are set to false, we default to leaving any unset variable to true (only exclude those languages).
  • If there are VALIDATE_[LANGUAGE] variables set to both true and false. It will fail.

This means that if you run the linter "out of the box", all languages will be checked. But if you wish to select or exclude specific linters, we give you full control to choose which linters are run, and won't run anything unexpected.

Name Description Default
VALIDATE_ANSIBLE Flag to enable or disable the linting process of the Ansible language. true
VALIDATE_ARM Flag to enable or disable the linting process of the ARM language. true
VALIDATE_BASH Flag to enable or disable the linting process of the Bash language. true
VALIDATE_BASH_EXEC Flag to enable or disable the linting process of the Bash language to validate if file is stored as executable. true
VALIDATE_CLOJURE Flag to enable or disable the linting process of the Clojure language. true
VALIDATE_CLOUDFORMATION Flag to enable or disable the linting process of the AWS Cloud Formation language. true
VALIDATE_COFFEE Flag to enable or disable the linting process of the Coffeescript language. true
VALIDATE_CSHARP Flag to enable or disable the linting process of the C# language. true
VALIDATE_CSS Flag to enable or disable the linting process of the CSS language. true
VALIDATE_DART Flag to enable or disable the linting process of the Dart language. true
VALIDATE_DOCKERFILE Flag to enable or disable the linting process of the Docker language. true
VALIDATE_DOCKERFILE_HADOLINT Flag to enable or disable the linting process of the Docker language. true
VALIDATE_EDITORCONFIG Flag to enable or disable the linting process with the editorconfig. true
VALIDATE_ENV Flag to enable or disable the linting process of the ENV language. true
VALIDATE_GO Flag to enable or disable the linting process of the Golang language. true
VALIDATE_GROOVY Flag to enable or disable the linting process of the language. true
VALIDATE_HTML Flag to enable or disable the linting process of the HTML language. true
VALIDATE_JAVA Flag to enable or disable the linting process of the language. true
VALIDATE_JAVASCRIPT_ES Flag to enable or disable the linting process of the Javascript language. (Utilizing: eslint) true
VALIDATE_JAVASCRIPT_STANDARD Flag to enable or disable the linting process of the Javascript language. (Utilizing: standard) true
VALIDATE_JSON Flag to enable or disable the linting process of the JSON language. true
VALIDATE_JSX Flag to enable or disable the linting process for jsx files (Utilizing: eslint) true
VALIDATE_KOTLIN Flag to enable or disable the linting process of the Kotlin language. true
VALIDATE_KUBERNETES_KUBEVAL Flag to enable or disable the linting process of Kubernetes descriptors with Kubeval true
VALIDATE_LATEX Flag to enable or disable the linting process of the LaTeX language. true
VALIDATE_LUA Flag to enable or disable the linting process of the language. true
VALIDATE_MARKDOWN Flag to enable or disable the linting process of the Markdown language. true
VALIDATE_OPENAPI Flag to enable or disable the linting process of the OpenAPI language. true
VALIDATE_PERL Flag to enable or disable the linting process of the Perl language. true
VALIDATE_PHP Flag to enable or disable the linting process of the PHP language. (Utilizing: PHP built-in linter) (keep for backward compatibility) true
VALIDATE_PHP_BUILTIN Flag to enable or disable the linting process of the PHP language. (Utilizing: PHP built-in linter) true
VALIDATE_PHP_PHPCS Flag to enable or disable the linting process of the PHP language. (Utilizing: PHP CodeSniffer) true
VALIDATE_PHP_PHPSTAN Flag to enable or disable the linting process of the PHP language. (Utilizing: PHPStan) true
VALIDATE_PHP_PSALM Flag to enable or disable the linting process of the PHP language. (Utilizing: PSalm) true
VALIDATE_PROTOBUF Flag to enable or disable the linting process of the Protobuf language. true
VALIDATE_PYTHON Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) (keep for backward compatibility) true
VALIDATE_PYTHON_PYLINT Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) true
VALIDATE_PYTHON_FLAKE8 Flag to enable or disable the linting process of the Python language. (Utilizing: flake8) true
VALIDATE_PYTHON_BLACK Flag to enable or disable the linting process of the Python language. (Utilizing: black) true
VALIDATE_POWERSHELL Flag to enable or disable the linting process of the Powershell language. true
VALIDATE_R Flag to enable or disable the linting process of the R language. true
VALIDATE_RAKU Flag to enable or disable the linting process of the Raku language. true
VALIDATE_RUBY Flag to enable or disable the linting process of the Ruby language. true
VALIDATE_SHELL_SHFMT Flag to enable or disable the linting process of Shell scripts. (Utilizing: shfmt) true
VALIDATE_SNAKEMAKE_LINT Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakemake --lint) true
VALIDATE_SNAKEMAKE_SNAKEFMT Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakefmt) true
VALIDATE_STATES Flag to enable or disable the linting process for AWS States Language. true
VALIDATE_SQL Flag to enable or disable the linting process of the SQL language. true
VALIDATE_TERRAFORM Flag to enable or disable the linting process of the Terraform language. true
VALIDATE_TERRAFORM_TERRASCAN Flag to enable or disable the linting process of the Terraform language for security related issues. true
VALIDATE_TERRAGRUNT Flag to enable or disable the linting process for Terragrunt files. true
VALIDATE_TSX Flag to enable or disable the linting process for tsx files (Utilizing: eslint) true
VALIDATE_TYPESCRIPT_ES Flag to enable or disable the linting process of the Typescript language. (Utilizing: eslint) true
VALIDATE_TYPESCRIPT_STANDARD Flag to enable or disable the linting process of the Typescript language. (Utilizing: standard) true
VALIDATE_XML Flag to enable or disable the linting process of the XML language. true
VALIDATE_YAML Flag to enable or disable the linting process of the YAML language. true

Artifacts

We use Junit's XML report to display error report directly in pipeline Test tab and in merge request widget.


License

MIT

Copyright 2021 thomasboni

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Changelog

  • latest (current -> 0.2.1):

    https://jobs.r2devops.io/super_linter.yml

0.2.1

https://jobs.r2devops.io/0.2.1/super_linter.yml

  • Improve documentation for $LINTER_RULES_PATH

  • Default value for $LINTER_RULES_PATH is now .linters

0.2.0

https://jobs.r2devops.io/0.2.0/super_linter.yml

  • Improve MR report by providing detailed information about issues found

  • Upgrade super-linter to version v3.14.3

  • Provide tap output files as artifacts

  • Improve output with newlines in report integration

0.1.0

https://jobs.r2devops.io/0.1.0/super_linter.yml

  • Initial version

-- ๐Ÿ”จ Maintainer: avatar Thomas Boni @thomasboni

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Job from R2Devops hub --> r2devops.io

stages:
  - static_tests

super_linter:
  stage: static_tests
  image:
    name: github/super-linter:v3.14.3
    entrypoint: [""]
  script:
    - /action/lib/linter.sh
  after_script:
    - npm install -g [email protected]${TAP_JUNIT_VERSION}
    - mkdir ${CONVERTED_OUTPUT_FOLDER}
    - cd $OUTPUT_FOLDER
    - for report in *; do
    -     'sed -i "s/message: \*\+/message: /g" $report' # workaround for https://github.com/dhershman1/tap-junit/issues/30#issuecomment-744462006
    -     cat $report | tap-junit -p -s "${REPORT_SUITE_TEST_NAME}" > ../${CONVERTED_OUTPUT_FOLDER}/${report}.xml # convert each tap file to junit xml
    -     sed -i 's/<failure message="\(.\+\)" type="fail">.*/<failure message="" type="fail">\n\1\n<\/failure>/g' ../${CONVERTED_OUTPUT_FOLDER}/${report}.xml # extract message to improve report display
    -     sed -i 's/\\n/\n/g' ../${CONVERTED_OUTPUT_FOLDER}/${report}.xml # add real newlines
    -     sed -i ':begin;$!N;s/<\/failure>\n<\/failure>/<\/failure>/;tbegin;P;D' ../${CONVERTED_OUTPUT_FOLDER}/${report}.xml # remove double </failure> that break the syntax in some reports
    - done
  variables:
    RUN_LOCAL: "true"
    DEFAULT_WORKSPACE: $CI_PROJECT_DIR
    DEFAULT_BRANCH: $CI_DEFAULT_BRANCH
    LINTER_RULES_PATH: ".linters"
    OUTPUT_FORMAT: "tap"
    OUTPUT_DETAILS: "detailed"
    OUTPUT_FOLDER: "super-linter.report"
    CONVERTED_OUTPUT_FOLDER: "converted-xml.report"
    TAP_JUNIT_VERSION: "4.0.0"
    REPORT_SUITE_TEST_NAME: "super_linter"
  artifacts:
    paths:
      - "${OUTPUT_FOLDER}/*.tap"
    when: always
    reports:
      junit: "${CONVERTED_OUTPUT_FOLDER}/*.xml"
  allow_failure: true


Last update: December 6, 2021