Package detail

npm-groovy-lint

nvuillam90.9kMIT15.2.0

Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files

groovy, lint, jenkinsfile, codenarc

readme

NPM GROOVY LINT (+ Format & Auto-fix)

Version Downloads/week Downloads/total Test codecov Mega-Linter GitHub contributors GitHub stars Docker Pulls Docker Stars License PRs Welcome

Groovy & Jenkinsfile Linter, Formatter and Auto-fixer

New: The article about the story of npm-groovy-lint, and why you should dive in open-source community !

Based on CodeNarc , this out of the box package allows to track groovy errors and correct a part of them

  • Use option --format to format & prettify source code
  • Use option --fix to activate autofixing of fixable rules

Easy to integrate in a CI/CD process (Jenkins Pipeline,CircleCI...) to lint your groovy or Jenkinsfile at each build :)

You can also use this package in :

image

See CHANGELOG

Any question, problem or enhancement request ? Ask here :)

Usage

    npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]
Parameter Type Description
-o
--output
String Output format (txt,json,sarif,html,xml), or path to a file with one of these extensions
Default: txt
Examples:
- "txt"
- "json"
- "./logs/myLintResults.txt"
- "./logs/myLintResults.sarif"
- "./logs/myLintResults.html"
- "./logs/myLintResults.xml"
Note: HTML and XML are directly from CodeNarc so using these formats will disable many npm-groovy-lint features
-l
--loglevel
String Log level (error,warning or info)
Default: info
--failon String Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Each failure level includes the more critical ones.
-c
--config
String Custom path to GroovyLint config file, or preset config `recommended\ recommended-jenkinsfile\ all<br/> Default: Browse current directory to find.groovylintrc.json\ js\ yml\ package.json` config file, or default npm-groovy-lint config if not defined.
Note: command-line arguments have priority on config file properties
--parse Boolean Try to compile the source code and return parse errors (since v5.7.0, default to true, use --no-parse to deactivate)
--format Boolean Format source code
--fix Boolean Automatically fix problems when possible
See Auto-fixable rules
-x
--fixrules
String Option for --fix argument: List of rule identifiers to fix (if not specified, all available fixes will be applied). See Auto-fixable rules
Examples:
- "SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"
- "Indentation"
--nolintafter Boolean When format or fix is called, a new lint is performed after the fixes to update the returned error list. If you just want the updated source code and do not care about the error logs, use this parameter to improve performances
-r
--rulesets
String RuleSet file(s) to use for linting, if you do not want to use recommended rules or .groovylintrc.js defined rules.
If list of comma separated strings corresponding to CodeNarc rules, a RuleSet file will be dynamically generated
Examples:
- "./config/codenarc/RuleSet-Custom.groovy"
- "./path/to/my/ruleset/files"
- Indentation{"spacesPerIndentLevel":2,"severity":"warning"},UnnecessarySemicolon,UnnecessaryGString
--rulesetsoverridetype String If list of rules sent in rulesets option, defines if they replace rules defined in .groovylintrc.json, or if they are appended
Values: replaceConfig (default), appendConfig
-s
--source
String If path and files are not set, you can directly send the source code string to analyze
--verbose Boolean More outputs in console, including performed fixes
-i
--ignorepattern
String Comma-separated list of Ant-style file patterns specifying files that must be ignored
Default: none
Example: "**/test/*""
--noserver Boolean npm-groovy-lint launches a microservice to avoid performance issues caused by loading java/groovy each time,that auto kills itself after 1h idle. Use this argument if you do not want to use this feature
--returnrules Boolean Return rules descriptions and URL if set
--javaexecutable String Override java executable to use
Default: java
Example: C:\Program Files\Java\jdk1.8.0_144\bin\java.exe
--javaoptions String Override java options to use
Default: "-Xms256m,-Xmx2048m"
--insight Boolean npm-groovy-lint collects anonymous usage statistics using amplitude, in order to make new improvements based on how users use this package.
Summary charts are available at https://tinyurl.com/groovy-stats.
Analytics obviously does not receive sensitive information like your code, as you can see in analytics.js.
If you want to enable anonymous usage statistics, use --insight option.
--codenarcargs String Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored)
Doc: http://codenarc.github.io/CodeNarc/codenarc-command-line.html
Example: npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml
-h
--help
Boolean Show help (npm-groovy-lint -h OPTIONNAME to see option detail with examples)
-v
--version
Boolean Show npm-groovy-lint version (with CodeNarc version)
-p
--path
String (DEPRECATED) Directory containing the files to lint
Example: ./path/to/my/groovy/files
-f
--files
String (DEPRECATED) Comma-separated list of Ant-style file patterns specifying files that must be included.
Default: "**/*.groovy,**/Jenkinsfile,**/*.gradle"
Examples:
- "**/Jenkinsfile"
- "**/*.groovy"
- "**/*.gradle"
- "**/mySingleFile.groovy"

Example calls

  • Lint a file
    npm-groovy-lint path/to/my/groovy/file.groovy
  • Lint multiple files
    npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
  • Lint directory
    npm-groovy-lint path/to/my/groovy
  • Lint pattern
    npm-groovy-lint path/to/my/groovy/*.groovy
  • Lint groovy with JSON output
    npm-groovy-lint --output json
  • Format files
    npm-groovy-lint --format my/path/to/file.groovy my/path/to/file2.groovy
  • Format and fix files
    npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy
  • Get formatted sources in stdout from stdin
    cat path/to/my/Jenkinsfile | npm-groovy-lint --format -
  • Advanced config
    npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt
  • Lint using core CodeNarc parameters and generate HTML report file
    npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"

Installation

    npm install -g npm-groovy-lint
  • If you have issues with v9, install previous version with npm install -g npm-groovy-lint@8.2.0
  • Node.js >= 12 is required to run this package. If you can't upgrade, you can use nvm to have different node versions on your computer
  • If you do not have java 17 installed on your computer, npm-groovy-lint will install them for you, so the first run may be long.

Configuration

Default rules definition (recommended, based on all tracks a lot of errors, do not hesitate to ignore some of them (like NoDef ou RequiredVariableType) if they are too mean for your project.

Create a file named .groovylintrc.json in the current or any parent directory of where your files to analyze are located

  • your-repo-root-folder
    • src
      • groovy
        • mygroovyfile.groovy
    • Jenkinsfile
    • .groovylintrc.json (do not forget the dot at the beginning of the file name)

If you are using VsCode Groovy Lint extension, just use QuickFix Ignore in all files and it will generate groovylintrc.json file.

Format

  • extends: Name of a base configuration (recommended, recommended-jenkinsfile, all)
  • rules: List of rules definition, following format "RuleSection.RuleName": ruleParameters or "RuleName": ruleParameters
    • RuleName: any of the CodeNarc rules
    • ruleParameters: can be just a severity override ( "off", "error", "warning", "info" ) , or a property list :

OR

  • codenarcRulesets: Comma-separated string containing the list of .xml or .groovy CodeNarc RuleSet files (in case you already are a CodeNarc user and do not wish to switch to npm-groovy-lint config format)

Examples

{
    "extends": "recommended",
    "rules": {
        "comments.ClassJavadoc": "off",
        "formatting.Indentation": {
            "spacesPerIndentLevel": 4,
            "severity": "info"
        },
        "UnnecessaryReturnKeyword": "error"
    }
}
{
    "extends": "recommended-jenkinsfile",
    "rules": {
        "CouldBeElvis": "off",
        "CouldBeSwitchStatement": "off",
        "VariableName": {
            "severity": "info"
        }
    }
}
{
    "codenarcRulesets": "RuleSet-1.groovy,RuleSet-2.groovy"
}

Disabling rules in source

You can disable rules directly by adding comment in file, using eslint style

To temporarily disable rule warnings in your file, use block comments in the following format:

/* groovylint-disable */

def variable = 1;

/* groovylint-enable */

You can also disable or enable warnings for specific rules:

/* groovylint-disable NoDef, UnnecessarySemicolon */

def variable = 1;

/* groovylint-enable NoDef, UnnecessarySemicolon */

To disable rule warnings in an entire file, put a /* groovylint-disable */ block comment at the top of the file:

/* groovylint-disable */

def variable = 1;

You can also disable or enable specific rules for an entire file:

/* groovylint-disable NoDef */

def variable = 1;

To disable all rules on a specific line, use a line or block comment in one of the following formats:

def variable = 1; // groovylint-disable-line

// groovylint-disable-next-line
def variable = 1;

/* groovylint-disable-next-line */
def variable = 1;

def variable = 1; /* groovylint-disable-line */

To disable a specific rule on a specific line:

def variable = 1; // groovylint-disable-line NoDef

// groovylint-disable-next-line NoDef
def variable = 1;

def variable = 1; /* groovylint-disable-line NoDef */

/* groovylint-disable-next-line NoDef */
def variable = 1;

To disable multiple rules on a specific line:

def variable = 1; // groovylint-disable-line NoDef, UnnecessarySemicolon

// groovylint-disable-next-line NoDef, UnnecessarySemicolon
def variable = 1;

def variable = 1; /* groovylint-disable-line NoDef, UnnecessarySemicolon */

/* groovylint-disable-next-line NoDef, UnnecessarySemicolon */
def variable = 1;

Auto-Fixable rules

  • AssignmentInConditional
  • BlankLineBeforePackage
  • BlockEndsWithBlankLine
  • BlockStartsWithBlankLine
  • BracesForClass
  • BracesForForLoop
  • BracesForIfElse
  • BracesForMethod
  • BracesForTryCatchFinally
  • ClassEndsWithBlankLine
  • ClassStartsWithBlankLine
  • ClosingBraceNotAlone
  • ConsecutiveBlankLines
  • DuplicateImport
  • ElseBlockBraces
  • ExplicitArrayListInstantiation
  • ExplicitLinkedListInstantiation
  • FileEndsWithoutNewline
  • IfStatementBraces
  • Indentation
  • IndentationClosingBraces
  • IndentationComments
  • InsecureRandom
  • MisorderedStaticImports
  • MissingBlankLineAfterImports
  • MissingBlankLineAfterPackage
  • NoTabCharacter
  • SpaceAfterCatch
  • SpaceAfterComma
  • SpaceAfterFor
  • SpaceAfterIf
  • SpaceAfterOpeningBrace
  • SpaceAfterSemicolon
  • SpaceAfterSwitch
  • SpaceAfterWhile
  • SpaceAroundOperator
  • SpaceBeforeClosingBrace
  • SpaceBeforeOpeningBrace
  • TrailingWhitespace
  • UnnecessaryDefInFieldDeclaration
  • UnnecessaryDefInMethodDeclaration
  • UnnecessaryDefInVariableDeclaration
  • UnnecessaryDotClass
  • UnnecessaryFinalOnPrivateMethod
  • UnnecessaryGString
  • UnnecessaryGroovyImport
  • UnnecessaryPackageReference
  • UnnecessaryParenthesesForMethodCallWithClosure
  • UnnecessarySemicolon
  • UnnecessaryToString
  • UnusedImport

Contribute to add more rules fixes :)

CI/CD

Mega-Linter

Latest npm-groovy-lint version is natively integrated in Mega-Linter, that you can use as GitHub action or in other CI tools This tool can also automatically apply fixes on Pull Request branches

CircleCI

# .circleci/config.yml
version: 2.1
jobs:
  lint:
    docker:
      - image: nvuillam/npm-groovy-lint
    steps:
      - checkout

      - run: |
          npm-groovy-lint

workflows:
  version: 2
  "lint":
    jobs:
       - lint

Jenkins

node {
    checkout scm
    docker.image('nvuillam/npm-groovy-lint').inside {
        sh 'npm-groovy-lint'
    }
}

Shell

Run with default settings

docker run --rm -u "$(id -u):$(id -g)" -w=/tmp -v "$PWD":/tmp nvuillam/npm-groovy-lint

Run with additional flags by simply appending them at after docker image name:

docker run --rm -u "$(id -u):$(id -g)" -w=/tmp -v "$PWD":/tmp nvuillam/npm-groovy-lint --failon warning --verbose

Other

You can run npm-groovy-lint using its official docker image

Use as module

You can import npm-groovy-lint into your NPM package and call lint & fix via module, using the same options than from npm-groovy-lint command line

Example

    npm install npm-groovy-lint --save
    const NpmGroovyLint = require("npm-groovy-lint/lib/groovy-lint.js");
    const fse = require("fs-extra");

    const npmGroovyLintConfig = {
        source: fse.readFileSync('./lib/example/SampleFile.groovy').toString(),
        fix: true,
        loglevel: 'warning',
        output: 'none'
    };
    const linter = new NpmGroovyLint(npmGroovyLintConfig, {});
    await linter.run();
    console.log(JSON.stringify(linter.lintResult));

Troubleshooting

If you have issues with MegaLinter, you can report it on the repository

To help reproducing, you can access advanced logs using DEBUG env variables

Examples:

  • DEBUG=npm-groovy-lint npm-groovy-lint ....
  • DEBUG=npm-groovy-lint,npm-groovy-lint-trace npm-groovy-lint ....

If you want to see what happens in CodeNarc Server, you can clone the repo and run locally npm server:run before running npm-groovy-lint: you'll see the live logs of the to CodeNarc Server for npm-groovy-lint.

Contribute

Contributions are very welcome !

Please follow Contribution instructions

Thanks

Other packages used

  • CodeNarc: groovy lint
  • java-caller: Easy call Java commands from Node
  • slf4j: logging for CodeNarc
  • log4j: logging for CodeNarc
  • GMetrics: Code measures for CodeNarc
  • Inspiration from eslint about configuration and run patterns

Contributors

nvuillam Dave Gallant warhod pawelkopka docwhat CatSue
Nicolas Vuillamy Dave Gallant Howard Lo Pawel Kopka docwhat CatSue

Release notes

See complete CHANGELOG

changelog

Changelog

Beta

[15.2.0] 2025-05-11

  • New script to automate the upgrade of JAR dependencies
  • Upgrade Groovy to 4.0.26
  • Upgrade node-java-caller to 4.2.1

[15.1.0] 2025-02-23

[15.0.2] 2024-08-30

  • Upgrade node-java-caller to fix bug with npm-groovy-lint --version on linux

[15.0.1] 2024-08-29

[15.0.0] 2024-08-26

  • Convert to ES Module
  • Upgrade to CodeNarc 3.5.0
  • Upgrade NodeJs to minimum version 20
  • Setup renovate
  • Upgrade dependencies, including base package node-java-caller
  • Upgrade MegaLinter to v8
  • Remove decode-html-entities dependency

[14.6.0] 2024-05-08

  • Upgrade node-java-caller to v4 to solve issues with Mac

[14.5.0] 2024-04-28

  • Change license to MIT

[14.4.1] 2024-04-16

  • Upgrade tar to avoid CVE

[14.4.0] 2024-03-27

  • Remove amplitude dependency and anonymous telemetry

[14.3.0] 2024-03-27

  • Upgrade amplitude dependency
  • Remove markdown links checks in internal CI (requirement covered by lychee)

[14.2.4] 2024-03-13

  • Fix issue with anonymous telemetry

[14.2.3] 2024-02-26

  • Fix #351: temp directories aren't cleaned up

[14.2.2] 2024-02-18

  • Fix console.warning is not a function

[14.2.1] 2024-02-09

  • fix: class not found request failure

[14.1.0] 2024-01-15

  • fix: missing parse errors with --noserver
  • Deactivate log file by default

[14.0.1] 2023-12-18

  • fix: analytics send failure error

[14.0.0] 2023-12-16

  • Fix data race on stdout capture which was corrupting the responses for overlapping requests by using a capturing plugin.
  • Fix data race on threads read and write which could result in missed cancellations and re-enable cancellation processing.
  • Ensure that threads are always removed in the case of write response exception.
  • Switch to jackson to enable efficient JSON encoding and decoding including raw embedding of CodeNarc result to avoid unnecessary processing.
  • Split out HTTP filters to their own files.
  • Use typed variables instead of def per linter recommendation.
  • Add early test for missing base directory to avoid running linter unnecessarily.
  • Fix parse failures for files which contain classes that only non-zero argument constructors.
  • Add gzip compression to reduce size of network traffic to improve performance
  • CI: Enhance MegaLinter config
  • CI: Upload expected sources as artifact if Check for changes job fails

[13.0.2] 2023-12-07

  • Remove useless console.log in sources.

[13.0.1] 2023-12-06

[13.0.0] 2023-11-26

  • BREAKING CHANGE: Upgrade CodeNarc to v3.4.0-alpha+3346775f

  • Major core architecture refactoring by the great Steven Hartland

    • Fix files specified on the command line not linting as expected due to the generated patterns not working as intended if relative path that contains a file and not a directory due to an issue with CodeNarc pattern processing.

    • Fix incompatible arguments passed to CodeNarc by:

      • Using arrays internally to avoid issues with spaces in arguments being interpreted incorrectly.
      • Stripping all quotes from string arguments as CodeNarc doesn't handle them correctly.
      • Enable automatic argument quoting on Windows.
    • Fix command line -ext extensions not being processed correctly and matching too many files as it was missing the prefix.

    • Ensure readFile and writeFile calls produce a stack trace on failure due to: https://github.com/nodejs/node/issues/30944.

    • Fix file delete race condition and variable clean up due to missing await.

    • Fix use of includes instead of exclude parameters.

  • Also:

    • Fixed Request failed logging
    • Fix README.md typo
    • Add additional useful debug logging
    • Run dev:pre-commit to update CHANGELOG.md
    • Add more cspell entries
    • Add missing items to CodeNarcServer.groovy usage
    • Re-enable tests which are now fixed
    • Override axios for security patch

Steven Hartland now becomes an official maintainer of npm-groovy-lint and vscode-groovy-lint !

[12.2.0] 2023-11-26

  • Upgrade java-caller dependency to 3.2.0 (Now handles Mac M1)
  • Output issue when error collecting CodeNarc version

[12.1.2] 2023-11-23

  • Revert update that output json when not requested

[12.1.1] 2023-11-19

  • Upgrade node-java-caller to v3.1.1

[12.1.0] 2023-11-18

  • Upgrade node-java-caller to v3.1.0

[12.0.1] 2023-11-06

[12.0.0] 2023-11-04

Many fixes, including an issue with IPV6 that made npm-groovy-lint crash on many machines, has been fixed by @stevenh ! Many thanks to him !

Breaking change: Minimum java version to Java 17

[11.1.1] 2022-10-31

  • Fix npm dependency minimatch

[11.1.0] 2022-10-31

  • Provide default range when only information available is a line number (#248)
  • New CodeNarc issues definition to calculate range in file
    • GStringExpressionWithinString
    • VariableName

[11.0.0] 2022-10-07

  • BREAKING CHANGE:--failon is now ìnfo by default, meaning exit code will be 1 if there is at least an info issue found. To have previous behaviour, use --failon none.
  • Display all files in console log only if --verbose is used (#243)

[10.1.0] 2022-08-15

  • Allow to send groovy sources as input from stdin
  • If --format or --fix option is used when source is sent as stdin, the result is output as stdout

Example: cat path/to/my/Jenkinsfile | npm-groovy-lint --format -

[10.0.3] 2022-08-15

  • Do not output results summary in console logs when output is json or sarif
  • Add test methods for SARIF called by CLI

[10.0.2] 2022-08-15

  • Fix error when absolute files sent as positional arguments on a linux system (#232)
  • Improve performances by calculating the longest command directory to send as base path to CodeNarc

[10.0.1] 2022-08-14

  • Fix error when files sent as positional arguments (#232)

[10.0.0] 2022-08-13

  • Core

    • Upgrade to CodeNarc v3.1.0
    • Accept list of directories / files as arguments (--path and --files become deprecated but are still usable)
      • Examples
        • Multiple files: npm-groovy-lint path/to/file1.groovy path/to/file2.groovy
        • Directory: npm groovy-lint path/to
        • Single file: npm-groovy-lint Jenkinsfile
        • Ant pattern(s): npm-groovy-lint path/to/**/*.groovy
    • Upgrade npm dependencies
    • CI: Upgrade MegaLinter to v6
    • Test classes for collecting error ranges
  • New error ranges rules

    • DuplicateNumberLiteral
    • DuplicateStringLiteral
    • MethodParameterTypeRequired
    • NoDef
    • SimpleDateFormatMissingLocale
    • SpaceInsideParenthesis
    • UnnecessaryPublicModifier
    • VariableTypeRequired
  • New fix rules

    • SpaceAfterMethodCallName
    • SpaceInsideParentheses
  • Bug Fixes

    • Wrongly calculated ranges are no more returned

[9.5.0] 2022-04-12

  • Disable Amplitude anonymous stats by default (use --insight to enable them)

[9.4.1] 2022-01-12

  • Upgrade node-sarif-builder to 2.0.1 and send npm-groovy-lint version in SARIF logs
  • New range detection for rules:
    • MethodReturnTypeRequired
    • UnusedImport

[9.4.0] 2022-01-11

[9.3.2] 2022-01-09

[9.3.1] 2022-01-06

[9.3.0] 2021-12-29

[9.2.0] 2021-12-23

  • Upgrade log4j dependencies because of (another) security issue (#196)

[9.1.0] 2021-12-14

[9.0.0] 2021-09-30

  • Upgrade to CodeNarc v2.2.0
  • Upgrade to Groovy v3.0.9
  • Reorganize sources test folder
  • Use java from 8 to 14 (install it if a later version is found)
  • Add timeouts in CI jobs
  • Add colors in error logs

[8.2.0] 2021-06-11

  • Upgrade dependencies advised by dependabot
  • Fix Mega-Linter errors found

[8.1.0] 2020-12-14

  • Exclude UnnecessaryGetter, FactoryMethodName, MethodReturnTypeRequired, and GStringExpressionWithinString in recommended-jenkinsfile (#140) (Felipe Santos)

[8.0.2] 2020-11-26

  • Fix documentation about --verbose and --version options
  • Use GitHub action to deploy to NPM

[8.0.1] 2020-11-19

  • Add a test case where variable includes if in its name for fix of rule SpaceAfterIf (Behlül Uçar)

[8.0.0] 2020-11-15

  • Upgrade to CodeNarc 2.0.0
    • Upgrade jars
    • Adapt Indentation rule to new behaviour
    • Use codenarc --ruleset argument instead of temp ruleset file
  • Replace super-linter by Mega-Linter
  • Fixes
    • (#127) Formatting breaks code, converting else if into elseif in some cases
    • Apply formatting rules also for --fix mode
    • Fix Markdown dead links
  • CI
    • Migrate from CircleCI to GitHub Actions: now tests are on Linux, Windows & MacOs
    • Activate spelling linter of Mega-Linter (+ .cspell.json file)
    • Add test cases for format and fix using CLI

[7.6.2] 2020-09-09

[7.6.0] 2020-09-08

  • Add GitHub Action GitHub Super-Linter to the repository
  • Update Dockerfile to pass Docker lint rules

[7.5.5] 2020-09-05

[7.5.4] 2020-09-04

  • Update frameworks detection

[7.5.1] 2020-09-02

  • Fix (#96) --fix adds redundant space into ${VARIABLE} (SpaceBeforeOpeningBrace fix rule error)
  • Fix grails framework detection
  • Fix Groovy parsing parsing when multiple files
  • Add .gvy and .nf in default browsed files extensions

[7.5.0] 2020-09-02

  • Add anonymous framework usage stats for Groovy core Team

[7.4.3] 2020-08-29

  • Upgrade java-caller to v2.2.0
    • Fix CLASSPATH on windows in case there are spaces in paths

[7.4.2] 2020-08-26

  • Fix (#90) When log level is specified number of linted files appear to be off

[7.4.1] 2020-08-23

  • (#88) Fix Docker image to allow to use extra parameters (by Howard Lo)

[7.4.0] 2020-08-17

[7.3.1] 2020-08-16

  • Add number of lines & reorganize anonymous statistics
  • Fix error type counters in anonymous statistics

[7.3.0] 2020-08-15

  • Allow to link to CodeNarc RuleSet files from .groovylintrc.json, using property "codenarcRulesets". Warning: doing so means that all other properties of config file will be ignored.

[7.1.1] 2020-08-11

[7.1.0] 2020-08-10

  • Externalize JavaCaller class into a separate package java-caller and use it

[7.0.0] 2020-08-07

  • New default recommended rules (activate/deactivate/change severity)
  • Allow to call --config recommended-jenkinsfile to use delivered .groovylintrc-recommended-jenkinsfile.json

[6.1.1] 2020-08-04

  • Fix SpaceAfterComma auto-fixing rule

[6.1.0] 2020-08-04

  • Java 14 compatibility (Closes #77)

[6.0.0] 2020-08-03

  • Upgrade to CodeNarc v1.6.1
    • Update list of rules
    • Use new CodeNarc JSON console Output instead of temporary XML files
    • Call CodeNarc to get its version instead of using npm-groovy-lint hardcoded value
  • Upgrade to GMetrics v1.1
  • Upgrade to Groovy v3.0.5
  • Add anonymous usage stats on types of errors found and fixed

[5.8.0] 2020-08-01

  • Fix & enhance anonymous statistics

[5.7.0] 2020-07-23

  • (#62) Check parse error in all files when called via CLI . Closes #69

[5.6.1] 2020-07-20

Fixes:

  • (#62) using a codenarc ruleset file seems to fail / groovylintrc is not codenarc compatible

[5.6.0] 2020-07-20

[5.5.1] 2020-07-15

  • Fixes
    • (#64) The contents of a string gets formatted unexpectedly

[5.5.0] 2020-07-09

  • Allow to override java executable and options (#54)

[5.4.2] 2020-07-09

  • Use os.EOL (#65) solving (#63) --fix for indentation adds CRLF line-endings to all files it touches

[5.4.1] 2020-07-01

  • CodeNarcServer listens to localhost only (#59) solving (#56)
  • Replace @analytics/segment with @amplitude/node for anonymous stats

[5.3.0] 2020-06-29

  • New option --failon , replacing --failonerror,--failonwarning and --failoninfo. It can take error, warning or info values (default: none). Previous options remain working but are deprecated and will be removed in a future major version
  • Update help for --fixrules option

[5.1.0] 2020-06-04

  • Install Java 8 using node-jre in case java version found is higher than Java 11 (CodeNarc compatibility is Java 8 to 11)

[5.0.3] 2020-05-30

  • Updated fix rules
    • Indentation
    • IndentationClosingBrace

[5.0.2] 2020-05-27

  • Avoid to apply wrong fix in case of CodeNarc false positive
  • New fix rules
    • BlankLineBeforePackage
  • Updated fix rules
    • BracesForIfElse
    • BracesForMethod
    • BracesForTryCatchFinally
    • ClassEndsWithBlankLine
    • ClassStartsWithBlankLine
    • MissingBlankLineAfterImports
    • MissingBlankLineAfterPackage
    • UnnecessaryGroovyImport
    • UnusedImport

[5.0.0] 2020-05-25

  • BIG BANG: Improve performances, compatibility, architecture and delivery
    • Get rid of jDeploy dependency
      • Use own java-caller.js for java commands
      • Update CircleCI config to use npm linkinstead of jdeploy install
    • Get rid of request dependency
      • Use axios for promisified http calls

[4.14.0] 2020-05-22

  • Send rule configuration to fix functions
  • Add .gradle files in default linted files
  • Fixes:
    • Missing number of linted files returned in summary
    • Try to call CodeNarcJava in case there is an error with CodeNarcServer call

[4.13.0] 2020-05-20

  • Manage to send options for rules sent in rulesets: Ex: Indentation{"spacesPerIndentLevel":2,"severity":"warning"},UnnecessarySemicolon
  • New parameter --rulesetsoverridetype : If list of rules sent in rulesets option, defines if they replace rules defined in .groovylintrc.json, or if they are appended

[4.12.0] 2020-05-18

  • Improve performances and avoid Unknown command: node error by using childProcess.fork to call CodeNarcServer

[4.11.1] 2020-05-16

  • Detect when crash is related to "node" or "java" command not found and return a human readable error message

[4.11.0] 2020-05-13

  • Add CI , rule overrides and crashes in anonymous insights for debugging investigation
  • When used as a module, never crash intentionally with throw, so when called by module, check linter.status and linter.error instead of try/catch
    • 0: ok
    • 1: expected error
    • 2: unexpected error
    • 9: if cancelled request

[4.10.0] 2020-05-12

[4.9.0] 2020-05-10

  • Add anonymous usage statistics using insight, in order to make new improvements based on how users use this package.
    • Note: Analytics obviously does not receive sensitive information like your code, as you can see in analytics.js. If you want to disable anonymous usage stats, use --no-insight option.

[4.8.0] 2020-05-08

  • New fix rules

    • AssignmentInConditional
    • DuplicateImport
    • ExplicitLinkedListInstantiation
    • InsecureRandom
    • UnnecessaryDefInVariableDeclaration
    • UnnecessaryDotClass
    • UnnecessaryFinalOnPrivateMethod
    • UnnecessaryInstantiationToGetClass
  • Updated fix rules

    • BracesForForLoop: False positive triggering messy code after fixing
    • UnnecessaryGString: Fix multiline replacements ( """ by ''' )
  • Fixes :

    • Launch JVM with high memory (-Xms256m -Xmx2048m) to improve performances on big files
    • Increase CodeNarcServ call timeout (+ Manage ETIMEOUT as result, not only ECONNREFUSED )
  • Utils

    • Allow regex in range functions

[4.7.0] 2020-05-06

  • New fix rules

    • BracesForClass
    • BracesForForLoop
    • BracesForIfElse
    • BracesForMethod
    • BracesForTryCatchFinally
    • ExplicitArrayListInstantiation
    • MissingBlankLineAfterImports
    • MissingBlankLineAfterPackage
  • Updated fix rules

    • UnnecessaryGString: Fix replacements containing \n and \r

[4.6.0] 2020-05-01

  • New fix rules

    • SpaceBeforeClosingBrace
    • UnnecessaryDefInMethodDeclaration
    • UnnecessaryPackageReference
    • UnnecessaryParenthesesForMethodCallWithClosure
  • Updated fix rules

    • MisorderedStaticImports: Fix @Grapes killer fixing rule
    • ElseBlockBrace :issue when instruction is on the same line than else

[4.5.5] 2020-04-30

  • Fixes
    • ignorepattern option not working #34

[4.5.2] 2020-04-29

  • Expose loadConfig() method to load rules when npm-groovy-lint is used as a library
  • Fixes
    • Missing temporary rulesets file missing
    • Handle better CodeNarcServer concurrent calls

[4.5.1] 2020-04-28

  • Fixes
    • Take in account user overridden indentation space (and other rules) when using --format option #31

[4.5.0] 2020-04-24

  • Configuration updates (#29):
    • New default config "recommended-jenkinsfile". Use it with argument --config recommended-jenkinsfile
    • Allow to directly target a config file name. Use it with argument --config /my/custom/path/.groovylintrc-custom-name.json
    • Allow to send a string key that will be used to find config file --config custom-name
  • Updated fix rules:
    • IfStatementBraces
    • ElseStatementBraces

[4.4.1] 2020-04-16

  • Fixes:
    • CodeNarcServer: Use cachedThreadPool instead of fixedThreadPool

[4.4.0] 2020-04-16

  • Cancel a CodeNarc Lint when a similar CodeNarcServer request is received (allowing onType mode for language servers)

[4.3.0] 2020-04-14

  • Allow to disable rules using comments in source in eslint style

[4.2.0] 2020-04-13

  • New option --parse: Capability to parse source code and return compilation errors
  • New fix rules (thanks CatSue !):
    • SpaceAfterSemicolon
    • SpaceAfterWhile

[4.1.0] 2020-04-12

  • Upgrade to Groovy 3.0.3
  • Automatic generation of fixable rules list for README
  • Refactor CodeNarcServer.groovy

[4.0.0] 2020-04-09

  • Fix issue affecting performances on Linux and MacOs

[3.3.0] 2020-04-06

  • When formatting, always run some custom npm-groovy-lint fix rules not corresponding to CodeNarc violations
  • Return CodeNarc and Groovy versions when --version options is called
  • Fixes
    • Lost indentation when applying some fix rules
  • Updated fix rules:
    • IndentationClosingBraces
    • IndentationComments
    • SpaceAfterCatch
    • SpaceAfterIf
  • New fix rules:
    • ClassEndsWithBlankLine
    • ClassStartsWithNewLine
    • SpaceAfterFor
    • SpaceAfterSwitch

[3.2.4] 2020-04-03

  • Error message in postinstall if env Node.js is lower than the minimal required (12)

[3.2.3] 2020-04-02

  • When If or Else brackets are fixed,trigger another rule lint & fix only with Indentation rules so CodeNarc recalculate them correctly
  • New option nolintafter: When format or fix is called, a new lint is performed after the fixes to update the error list. If you just want the updated source code and do not care about the error logs, use this parameter to improve performances
  • Fixes
    • Manage correctly options failonerror, failonwarning and failoninfo
    • npm-groovy-lint -version now returns version from package.json
  • Mocha tests updates:
    • Add stats on calls to CodeNarc (globalThis.codeNarcCallsCounter and globalThis.codeNarcCalls, activated if globalThis.codeNarcCallsCounter is set to 0 before calling NmpGroovyLint)
    • Factorize test classes common code in module helper/common.js
    • Use a smaller groovy file for test classes when not impacting the tests quality

[3.2.2] 2020-03-31

  • New option returnrules if you want to return rules descriptions and documentation url in results
  • Use npm ci instead of npm install in CircleCI build

[3.2.1] 2020-03-29

  • Return rules descriptions in results
  • New option nolintafter: do not lint again a format or a fix, as the client prefers to request it
  • Fixes
    • Issue #13: False positive error ClassNameSameAsFileName
    • Sometimes returning wrong .groovylint.json config file

[3.2.0] 2020-03-26

  • New option "--format", allowing to reformat source code (using .groovylintrc-format.json)
  • Update default recommended rules

[3.1.3] 2020-03-22

[3.1.2] 2020-03-22

  • New Fix rules:
    • BlockEndsWithBlankLine
    • BlockStartsWithBlankLine
    • MisorderedStaticImports
    • SpaceAfterIf
  • Fix: Update correctly the lineNb & ranges of next errors after an error has been fixed
  • Do not return rules tests if call is not from a test file
  • Fix rules:
    • ElseBlockBraces
    • IfStatementBraces
    • SpaceAroundOperator
    • UnusedImport

[3.1.1] 2020-03-20

  • New Fix rules:
    • BlockEndsWithBlankLine
    • BlockStartsWithBlankLine
    • MisorderedStaticImports
    • SpaceAfterIf
  • Updated Fix rules:
    • SpaceAroundOperator

[3.1.0] 2020-03-18

  • Test suites: Improve reliability & logs for rule fixes tests (detected numerous bugs, now corrected)
  • Send computed range to fix functions
  • Updated Fix rules:
    • ClosingBraceNotAlone
    • ElseBlockBraces
    • IfStatementBraces
    • NoTabCharacter
    • SpaceAfterComma
    • SystemExit
    • TrailingWhitespace
    • UnnecessaryGroovyImport
    • UnusedImport

[3.0.1] 2020-03-17

  • Add new test suites: errors.test.js and miscellaneous.test.js
  • Use JSON as default GroovyLint configuration file type
  • Order of fixable rules must be defined in groovy-lint-rules.js
  • Do not load rules test data except during tests
  • Do not lint again after a call to fixErrors on an existing NpmGroovyLint instance (except if lintAgainAfterFix : true is sent in options)
  • Fix: Deletion of temp RuleSite file
  • Fix: UnnecessarySemiColon rule
  • Fix: ClosingBraceNotAlone rule

[3.0.0] 2020-03-15

  • Local microservice "CodeNarcServer" called via Http by npm-groovy-lint, to avoid loading all groovy/java classes at each lint request. This microservice auto-kills itself after one hour idle.
  • Capability to define RuleSets in argument or js/json/yml config file formats instead of groovy/xml RuleSet format
  • Test classes for rules fix (before / after fix defined in rule definitions)
  • Add debug logs (use it by setting DEBUG env variable , ex: DEBUG=npm-groovy-lint npm-groovy-lint args...)
  • Update lines and ranges of other errors after a fix updated the number of lines
  • Generate automatically .groovylintrc-all.js during build
  • Split rules definition into files instead of all in a huge single file
  • Reorganize groovy-lint.js code, using codenarc-factory.js and codenarc-caller.js
  • New lib utils.js that can be used by rules definition
  • Fix: Crash when there was no error found in a file
  • Fix: Remove Promise error display in log after launching CodeNarcServer
  • Fix: Add more options exclusivity arguments rules
  • Removed "Groovy", "Jenkinsfile" and "All" identifiers for --rulesets arguments. Please now use .groovylintrc.js configuration

[2.2.0] 2020-02-28

  • Capability to call NpmGroovyLint with options as object, not only command line arguments
  • New option "source", allowing to call NpmGroovyLint with the groovy code as a string , not only path & files pattern
  • Run lint again after fix all errors, to get updated lintResult
  • Add gitattributes to normalized line-endings (thanks docwhat)
  • API: fix only some errors after an initial lint (better performances)
  • Return error range in files for some rules in JSON or API result (will be useful for the VsCode extension currently developed)
  • Define range function for existing rules, new fixable rules

[2.0.1] - 2020-02-21

  • Capability to fix errors
    • ConsecutiveBlankLines
      • Indentation (IfStatementBraces and ElseIfStatementBraces must be manually fixed to have correct indentation)
      • IndentationComments (custom npm-groovy-rule triggered by Indentation rule)
      • IndentationClosingBrace (custom npm-groovy-rule triggered by Indentation rule)
      • NoTabCharacter
      • SpaceAfterCatch
      • SpaceAfterOpeningBrace
      • SpaceAroundOperator
      • SpaceAfterComma
      • SpaceBeforeOpeningBrace
      • UnnecessaryDefInFieldDeclaration
      • UnnecessaryGString
      • UnnecessaryPublicModifier
      • UnnecessarySemicolon
      • TrailingWhitespace
  • Log formatting with severity colors and summary table
  • Default recommended RuleSets for Groovy and Jenkins
  • Progress bar in console
  • More code coverage with test campaigns
  • New Capability to call NpmGroovyLint from another package (VsCode extension development in progress ^^)
  • Refactored command line arguments ( simpler, but different from CodeNarc ones : retro-compatibility with CodeNarc arguments assured if you add --codenarcargs)
  • Upgrade to CodeNarc v1.5
  • Upgrade to Groovy v3.0.1
  • Refactored documentation with detailed arguments description & examples

Before

  • I wasn't serious enough to keep a changelog, sorry !