Skip to content

npm-groovy-lint

npm-groovy-lint documentation

npm-groovy-lint - GitHub

Configuration in Mega-Linter

Variable Description Default value
GROOVY_NPM_GROOVY_LINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src|lib)
Include every file
GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test|examples)
Exclude no file
GROOVY_NPM_GROOVY_LINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".groovy", ".gvy", ".gradle", ".nf"]
GROOVY_NPM_GROOVY_LINT_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
["Jenkinsfile"]
GROOVY_NPM_GROOVY_LINT_CONFIG_FILE npm-groovy-lint configuration file name
Use LINTER_DEFAULT to let the linter find it
.groovylintrc.json
GROOVY_NPM_GROOVY_LINT_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter default rules
GROOVY_NPM_GROOVY_LINT_DISABLE_ERRORS Run linter but consider errors as warnings false
GROOVY_NPM_GROOVY_LINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use npm-groovy-lint in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Visual Studio Code VsCode Groovy Lint Install in VsCode

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 84 Docker Image Size (tag) Docker Pulls
ci_light Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML 12 Docker Image Size (tag) Docker Pulls
dart Optimized for DART based projects 38 Docker Image Size (tag) Docker Pulls
documentation Mega-Linter for documentation projects 37 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 43 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 39 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 38 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 46 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 41 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 44 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 38 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 38 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 38 Docker Image Size (tag) Docker Pulls
scala Optimized for SCALA based projects 38 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 38 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 40 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .groovy, .gvy, .gradle, .nf
  • File names (regex): Jenkinsfile

Example calls

npm-groovy-lint --path . --files myfile.groovy
npm-groovy-lint --path . --files myfile.groovy -c .groovylintrc.json
npm-groovy-lint --path . --files myfile.groovy -c .groovylintrc.json --fix

Help content

npm-groovy-lint [options]

  -p, --path path::String      Directory containing the files to lint (default: current directory) - default: .
  -f, --files String           Comma-separated list of Ant-style file patterns specifying files that must be included
  -s, --source String          Source text to lint (if no path/files arguments)
  --sourcefilepath String      Full path of the file whose content is sent in source argument
  --parse                      Try to parse the source code with GroovyShell and return errors (use argument --no-parse if you want to deactivate)
  -c, --config String          Custom path to directory containing GroovyLint config file.
 Default: Found groovylintrc.js/json/yml/package.json config file, or default npm-groovy-lint config if not defined.
Note: command-line arguments have priority on config file properties - default: /
  --format                     Format source code
  --fix                        Automatically fix problems when possible
  -x, --fixrules String        Option for --fix argument: List of rule identifiers to fix (if not specified, all available fixes will be applied) - default: all
  -i, --ignorepattern String   Comma-separated list of Ant-style file patterns specifying files that must be ignored. Default: none
  -r, --rulesets String        RuleSet file(s) to use for linting. If it is a directory, all rulesets will be used. RuleSet file definition: http://codenarc.github.io/CodeNarc/codenarc-creating-ruleset.html. If not specified, npm-groovy-script default one will be used. Can also be a list of rule identifiers with parameters
  --rulesetsoverridetype String  If list of rules sent in rulesets option, defines if they replace rules defined in .groovylintrc.json, or if they are appended - either: replaceConfig or appendConfig - default: replaceConfig
  -o, --output String          Output format (txt,json,html,xml), or path to a file with one of these extensions - default: txt
  -l, --loglevel String        Log level (error,warning,info) - either: error, warning, or info - default: info
  --verbose                    More outputs in console, including performed fixes
  --failon String              Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Every failure level includes the more critical ones. - either: error, warning, info, or none - default: none
  --failonerror                (Deprecated) Fails if at least one error is found
  --failonwarning              (Deprecated) Fails if at least one warning is found
  --failoninfo                 (Deprecated) Fails if at least one error is found
  --codenarcargs               Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored). Doc: http://codenarc.github.io/CodeNarc/codenarc-command-line.html
  --noserver                   For better performances, npm-groovy-lint runs a local server to eep CodeNarc alive instead of loading java/groovy at each call. If you don't want that, send this argument
  --serverhost String          If use of CodeNarc server, host where is the CodeNarc server (default: localhost) - default: http://localhost
  --serverport String          If use of CodeNarc server, port of the CodeNarc server (default: 7484) - default: 7484
  -j, --javaexecutable String  If you do not want to use default java executable to run CodeNarcServer, you can override it - default: java
  --javaoptions String         Override java options - default: -Xms256m,-Xmx2048m
  --killserver                 Terminate the CodeNarcServer if running
  --nolintafter                Do not lint again after format and fix options (useful for client calling Npm Groovy Lint)
  --returnrules                Return rule descriptions and url if this argument is set
  --insight                    npm-groovy-lint collects anonymous usage statistics using package https://www.npmjs.com/package/insight. If you do not want to share them, use --no-insight option
  -h, --help                   Show help (npm-groovy-lint -help OPTIONNAME to see option detail)
  -v, --version                Show version

Installation on mega-linter Docker image

Example success log

Results of npm-groovy-lint linter (version 8.0.2)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/groovy_npm_groovy_lint/
-----------------------------------------------

[SUCCESS] .automation/test/groovy/groovy_good_01.groovy
    .automation/test/groovy/groovy_good_01.groovy


    npm-groovy-lint results in 1 linted files:
    ┌─────────┬───────────┬─────────────┐
    │ (index) │ Severity  │ Total found │
    ├─────────┼───────────┼─────────────┤
    │    0    │  'Error'  │      0      │
    │    1    │ 'Warning' │      0      │
    │    2    │  'Info'   │      0      │
    └─────────┴───────────┴─────────────┘

Example error log

Results of npm-groovy-lint linter (version 8.0.2)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/groovy_npm_groovy_lint/
-----------------------------------------------

[ERROR] .automation/test/groovy/groovy_bad_01.groovy
    .automation/test/groovy/groovy_bad_01.groovy
      4     error    Unexpected input: '$' @ line 4, column 16.  NglParseError           
      2     info     Line ends with whitespace characters  TrailingWhitespace      


    npm-groovy-lint results in 1 linted files:
    ┌─────────┬───────────┬─────────────┐
    │ (index) │ Severity  │ Total found │
    ├─────────┼───────────┼─────────────┤
    │    0    │  'Error'  │      1      │
    │    1    │ 'Warning' │      0      │
    │    2    │  'Info'   │      1      │
    └─────────┴───────────┴─────────────┘
    Failure: 1 error(s) have been found 
     0 warning(s) have been found 
     1 info(s) have been found