# npm-groovy-lint

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

Latest version **19.0.1** (published 2026-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install npm-groovy-lint
pnpm add npm-groovy-lint
yarn add npm-groovy-lint
bun add npm-groovy-lint
```

Provides the command `npm-groovy-lint`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; large bundle.

## Facts

| | |
|---|---|
| Version | 19.0.1 |
| Published | 2026-11-08 |
| First published | 2020-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.13.0 |
| Dependencies | 4 |
| Unpacked size | 18.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 245 |
| Author | Nicolas Vuillamy |
| Maintainers | nvuillam |
| Keywords | groovy, lint, jenkinsfile, codenarc, format, linter, formatter, auto-fix, refactor, gradle |

## Links

- npm: https://www.npmjs.com/package/npm-groovy-lint
- Repository: https://github.com/nvuillam/npm-groovy-lint
- Homepage: https://github.com/nvuillam/npm-groovy-lint#readme
- Issues: https://github.com/nvuillam/npm-groovy-lint/issues
- npm.io page: https://npm.io/package/npm-groovy-lint

## Dependencies (4)

- [js-yaml](https://npm.io/package/js-yaml.md) ^5.0.0
- [optionator](https://npm.io/package/optionator.md) ^0.9.0
- [java-caller](https://npm.io/package/java-caller.md) ^6.1.0
- [node-sarif-builder](https://npm.io/package/node-sarif-builder.md) ^5.0.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 19.0.1 (latest) — 2026-11-08
- 18.0.1-beta-202610311125.0 (beta) — 2026-10-31
- 19.0.0 — 2026-10-31
- 18.0.1-beta-202610311120.0 — 2026-10-31
- 18.0.1-beta-202608101733.0 — 2026-08-10
- 18.0.0 — 2026-06-30
- 17.0.5 — 2026-05-07
- 17.0.4 — 2026-04-15
- 17.0.4-beta-202604150506.0 — 2026-04-15
- 17.0.3 — 2026-03-31
- 17.0.2 — 2026-03-29
- 17.0.0 — 2026-02-28
- 16.2.0 — 2026-01-24
- 16.1.2-beta-202601241036.0 — 2026-01-24
- 16.1.2-beta-202601241018.0 — 2026-01-24
- … 214 more at https://npm.io/package/npm-groovy-lint/versions

## README

<!-- markdownlint-disable MD013 MD033 MD034 -->
# NPM GROOVY LINT (+ Format & Auto-fix)

[![Version](https://img.shields.io/npm/v/npm-groovy-lint.svg)](https://npmjs.org/package/npm-groovy-lint)
[![Downloads/week](https://img.shields.io/npm/dw/npm-groovy-lint.svg)](https://npmjs.org/package/npm-groovy-lint)
[![Downloads/total](https://img.shields.io/npm/dt/npm-groovy-lint.svg)](https://npmjs.org/package/npm-groovy-lint)
[![Test](https://github.com/nvuillam/npm-groovy-lint/workflows/Test/badge.svg?branch=master)](https://github.com/nvuillam/npm-groovy-lint/actions?query=workflow%3ATest+branch%3Amaster)
[![codecov](https://codecov.io/gh/nvuillam/npm-groovy-lint/branch/master/graph/badge.svg)](https://codecov.io/gh/nvuillam/npm-groovy-lint)
[![Mega-Linter](https://github.com/nvuillam/npm-groovy-lint/actions/workflows/mega-linter.yml/badge.svg?branch=main)](https://github.com/nvuillam/npm-groovy-lint/actions/workflows/mega-linter.yml)
[![GitHub contributors](https://img.shields.io/github/contributors/nvuillam/npm-groovy-lint.svg)](https://gitHub.com/nvuillam/npm-groovy-lint/graphs/contributors/)
[![GitHub stars](https://img.shields.io/github/stars/nvuillam/npm-groovy-lint?label=Star&maxAge=2592000)](https://github.com/nvuillam/npm-groovy-lint/stargazers)
[![Docker Pulls](https://img.shields.io/docker/pulls/nvuillam/npm-groovy-lint)](https://hub.docker.com/r/nvuillam/npm-groovy-lint)
[![Docker Stars](https://img.shields.io/docker/stars/nvuillam/npm-groovy-lint)](https://hub.docker.com/r/nvuillam/npm-groovy-lint)
[![License](https://img.shields.io/npm/l/npm-groovy-lint.svg)](https://github.com/nvuillam/npm-groovy-lint/blob/master/package.json)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)<!-- gh-dependents-info-used-by-start -->
[![Generated by github-dependents-info](https://img.shields.io/static/v1?label=Used%20by&message=71&color=informational&logo=slickpic)](https://github.com/nvuillam/npm-groovy-lint/blob/main/docs/github-dependents-info.md)<!-- gh-dependents-info-used-by-end -->

## Groovy & Jenkinsfile Linter, Formatter and Auto-fixer

***New: The [article about the story of npm-groovy-lint](https://nicolas.vuillamy.fr/a-groovy-journey-to-open-source-during-covid-19-npm-groovy-lint-8d88c7eecebc), and why you should dive in open-source community !***

Based on [CodeNarc](http://codenarc.github.io/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 :

- [Visual Studio Code Groovy Lint extension](https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint)
- [Mega-Linter](https://nvuillam.github.io/mega-linter/) (can be used as GitHub Action, and lints all other languages and formats)
- [Docker Image](#other)

![image](https://github.com/nvuillam/npm-groovy-lint/raw/main/docs/assets/images/npm-groovy-lint-results.png)

See [CHANGELOG](https://github.com/nvuillam/npm-groovy-lint/blob/master/CHANGELOG.md)

Any **question**, **problem** or **enhancement request** ? Ask in the [**npm-groovy-lint issue tracker**](https://github.com/nvuillam/npm-groovy-lint/issues) :)

## Usage

```shell
    npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]
```

| Parameter               | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|-------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -o<br/> --output        | String  | Output format (txt,json,sarif,html,xml), or path to a file with one of these extensions<br/> Default: `txt`<br/> Examples:<br/> - `"txt"`<br/> - `"json"`<br/> - `"./logs/myLintResults.txt"`<br/> - `"./logs/myLintResults.sarif"`<br/> - `"./logs/myLintResults.html"`<br/> - `"./logs/myLintResults.xml"`<br/>Note: HTML and XML are directly from CodeNarc so using these formats will disable many npm-groovy-lint features                                                                                                  |
| -l<br/> --loglevel      | String  | Log level (error,warning or info)<br/>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<br/> --config        | String  | Custom path to [GroovyLint config file](#configuration), or a [preset](#rule-presets) name `recommended\|advanced\|all\|format\|grails\|tests\|jenkinsfile\|recommended-jenkinsfile`<br/> Default: Browse current directory to find `.groovylintrc.json\|js\|yml\|package.json` config file, or default npm-groovy-lint config if not defined.<br/>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<br/> See [Auto-fixable rules](#auto-fixable-rules)                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -x<br/> --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](#auto-fixable-rules) <br/> Examples:<br/> - `"SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"`<br/> - `"Indentation"`<br/>                                                                                                                                                                                                                                              |
| --fixrulesexclude       | String  | Option for --fix argument: Comma-separated list of rule identifiers to exclude from fixes (if not specified, none are excluded). If used with --fixrules, exclusion is applied last (excluded rules cancel included rules). See [Auto-fixable rules](#auto-fixable-rules) <br/> Examples:<br/> - `"Indentation,IndentationClosingBraces,BracesForIfElse"`<br/> - `"UnnecessarySemicolon,SpaceAfterComma"`<br/>                                                                                                                    |
| --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<br/> --rulesets      | String  | [RuleSet file(s)](http://codenarc.github.io/CodeNarc/codenarc-creating-ruleset.html) to use for linting, if you do not want to use recommended rules or .groovylintrc.js defined rules.<br/>If list of comma separated strings corresponding to CodeNarc rules, a RuleSet file will be dynamically generated </br>  Examples:<br/> - `"./config/codenarc/RuleSet-Custom.groovy"`<br/> - `"./path/to/my/ruleset/files"`<br/>- `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<br/> Values: `replaceConfig` (default), `appendConfig`                                                                                                                                                                                                                                                                                                                                             |
| -s<br/> --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<br/> --ignorepattern | String  | Comma-separated list of Ant-style file patterns specifying files that must be ignored<br/> Default: none<br/> 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  <br/>Default: java<br/>Example: C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java.exe                                                                                                                                                                                                                                                                                                                                                                                                             |
| --javaoptions           | String  | Override java options to use  <br/>Default: "-Xms256m" and a max heap of half the available memory, between "-Xmx2048m" and "-Xmx4096m"                                                                                                                                                                                                                                                                                                                                                                                           |
| -P<br/> --parallelism   | Int     | Number of threads used to analyse files in parallel (default: auto, max 4). Use 1 to disable                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| --insight               | Boolean | npm-groovy-lint collects anonymous usage statistics using [amplitude](https://www.npmjs.com/package/amplitude), in order to make new improvements based on how users use this package. <br/> Summary charts are available at [https://tinyurl.com/groovy-stats](https://tinyurl.com/groovy-stats).<br/> Analytics obviously does not receive sensitive information like your code, as you can see in analytics.js.<br/> 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)<br/> Doc: <http://codenarc.github.io/CodeNarc/codenarc-command-line.html><br/> Example: `npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml`                                                                                                                                                                                  |
| -h<br/> --help          | Boolean | Show help (npm-groovy-lint -h OPTIONNAME to see option detail with examples)                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -v<br/> --version       | Boolean | Show npm-groovy-lint version (with CodeNarc version)                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -p<br/> --path          | String  | (DEPRECATED) Directory containing the files to lint<br/> Example: `./path/to/my/groovy/files`                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| -f<br/> --files         | String  | (DEPRECATED) Comma-separated list of Ant-style file patterns specifying files that must be included.<br/> Default: `"**/*.groovy,**/Jenkinsfile,**/*.gradle"`<br/>Examples:<br/> - `"**/Jenkinsfile"`<br/> - `"**/*.groovy"`<br/> - `"**/*.gradle"`<br/> - `"**/mySingleFile.groovy"`                                                                                                                                                                                                                                             |

### Example calls

- Lint a file

```shell
    npm-groovy-lint path/to/my/groovy/file.groovy
```

- Lint multiple files

```shell
    npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
```

- Lint directory

```shell
    npm-groovy-lint path/to/my/groovy
```

- Lint pattern

```shell
    npm-groovy-lint path/to/my/groovy/*.groovy
```

- Lint groovy with JSON output

```shell
    npm-groovy-lint --output json
```

- Format files

```shell
    npm-groovy-lint --format my/path/to/file.groovy my/path/to/file2.groovy
```

- Format and fix files

```shell
    npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy
```

- Fix files but exclude specific rules (useful for avoiding buggy indentation rules)

```shell
    npm-groovy-lint --fix --fixrulesexclude Indentation,IndentationClosingBraces,BracesForIfElse my/path/to/file.groovy
```

- Fix only specific rules

```shell
    npm-groovy-lint --fix --fixrules SpaceAfterComma,TrailingWhitespace,UnusedImport my/path/to/file.groovy
```

- Get formatted sources in stdout from stdin

```shell
    cat path/to/my/Jenkinsfile | npm-groovy-lint --format -
```

- Advanced config

```shell
    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

```shell
    npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"
```

## Installation

```shell
    npm install -g npm-groovy-lint
```

- If you have issues with v19, install the previous version with `npm install -g npm-groovy-lint@18` and see [Migrating from v18 to v19](#migrating-from-v18-to-v19)
- Node.js >= 22.13.0 is required to run this package. If you can't upgrade, you can use [nvm](https://github.com/nvm-sh/nvm) to have [different node versions on your computer](https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/)
- Java 17 or higher is required. If you do not have a compatible Java version installed on your computer, npm-groovy-lint will install Java 17 for you, so the first run may be long.

## Migrating from v18 to v19

v19 is about 3 to 18 times faster, but it changes what a lint reports by default. Check these points when you upgrade.

### 1. Stop the old CodeNarc server

npm-groovy-lint keeps a CodeNarc server running in the background. Stop it **before** upgrading:

```shell
npm-groovy-lint --killserver
npm install -g npm-groovy-lint@19
```

If you forgot, run `npm-groovy-lint --killserver` again with v19: it stops both old and new servers. A v18 `--killserver` cannot stop a v19 server, so don't mix versions in the same environment (kill the process by its PID, or let it stop by itself after 1 hour idle).

### 2. Expect fewer violations by default

The default preset, `recommended`, now reports only what is **most likely a mistake** (149 rules). v18 reported nearly every CodeNarc rule (390 rules), including style and layout. See [Rule presets](#rule-presets).

What you may notice:

- **Fewer violations, and builds that used to fail may now pass.** Style rules (`NoDef`, `*TypeRequired`, naming, `Unnecessary*`, size thresholds, Javadoc...) and layout rules (indentation, braces, spacing) are no longer reported by default.
- **`--fix` and `--format` still fix layout exactly as before.** Layout is fixed, just not reported.
- **Inline comments such as `// groovylint-disable-next-line NoDef`** still work. They simply have nothing to hide for rules that are no longer enabled.

To get the old rules back, set `extends` in your `.groovylintrc.json`:

| You want                                          | Set                                                 |
|---------------------------------------------------|-----------------------------------------------------|
| Layout violations reported too                    | `{ "extends": ["recommended", "format"] }`          |
| Style and layout reported (Groovy idioms, naming) | `{ "extends": "advanced" }`                         |
| The closest to the v18 default                    | `{ "extends": "all" }` (see below)                  |
| Grails or JUnit/Spock rules                       | `{ "extends": ["recommended", "grails", "tests"] }` |

v18's default was `all` with a few changes. To get it back as closely as possible:

```json
{
    "extends": "all",
    "rules": {
        "convention.TrailingComma": "off",
        "formatting.SpaceAroundMapEntryColon": "off",
        "logging.Println": "off",
        "unnecessary.UnnecessaryReturnKeyword": "off"
    }
}
```

### 3. Check your preset names

- `recommended`, `all`, `format` and `recommended-jenkinsfile` still exist.
- The `grails`, `tests` and `jenkinsfile` presets now **include `recommended`**. `-c jenkinsfile` alone is a full lint, not only the Jenkinsfile-specific rules.
- `extends` accepts a list, merged from left to right: `{ "extends": ["advanced", "jenkinsfile"] }`.

### 4. Check your command lines and environment

| If you use                                | In v19                                                                                                                                                |
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| Node.js older than 22.13                  | Upgrade Node.js to 22.13 or higher                                                                                                                    |
| `--files`                                 | It was silently ignored since v13: every file under `--path` was linted. It is now applied, so only matching files are linted                         |
| `DEBUG=npm-groovy-lint` to get debug logs | Use `NODE_DEBUG=npm-groovy-lint` instead                                                                                                              |
| `--serverhost http://localhost`           | The default is now `http://127.0.0.1`. Keep your value only if you really run the server elsewhere                                                    |
| A machine or container with little memory | The server's max heap is now half the available memory, between 2048m (the v18 value) and 4096m. Set `--javaoptions "-Xms256m,-Xmx1024m"` to use less |
| Many cores, and you want one thread       | Files are now analysed on up to 4 threads. Use `--parallelism 1` to analyse one file at a time                                                        |

## Configuration

### Rule presets

npm-groovy-lint ships tiered presets, the way ESLint separates `eslint:recommended` from the rest. The default is [`recommended`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-recommended.json).

| Preset                                                                                                                  | Rules | What it reports                                                                                                                                |
|-------------------------------------------------------------------------------------------------------------------------|-------|------------------------------------------------------------------------------------------------------------------------------------------------|
| [`recommended`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-recommended.json) *(default)* | 149   | Only what is **most likely a mistake**: code that does not do what its author meant, dead code, security and concurrency hazards, misused APIs |
| [`advanced`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-advanced.json)                   | 344   | `recommended` **+ style**: Groovy idioms, design, naming conventions, complexity thresholds, Javadoc and layout                                |
| [`all`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-all.json)                             | 390   | Every CodeNarc rule, including those that do nothing until you configure them (`IllegalRegex`, `RequiredString`...)                            |
| [`format`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-format.json)                       | 40    | Layout only: indentation, braces, blank lines, spacing. This is what `--format` and `--fix` apply                                              |

Plus three framework add-ons: [`grails`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-grails.json), [`tests`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-tests.json) (JUnit and Spock) and [`jenkinsfile`](https://github.com/nvuillam/npm-groovy-lint/blob/master/lib/.groovylintrc-jenkinsfile.json) (relaxes the rules a pipeline always breaks). Each extends `recommended`, so using one standalone (`-c jenkinsfile`) is a full lint; to compose them on top of another tier, list them after it:

```json
{
    "extends": ["advanced", "grails", "tests"]
}
```

Presets are merged from left to right, and your own `rules` always win.

**`recommended` reports no layout at all** — that belongs to `format`. Layout is still **fixed**, just not reported: `npm-groovy-lint --fix` applies the `format` rules on top of the lint ruleset, so it repairs indentation, braces and spacing exactly as before, and `--format` is unchanged. A rule you disable in your own config stays disabled under `--fix`.

To report layout too, add the `format` preset — or take everything with `advanced`:

```json
{
    "extends": ["recommended", "format"]
}
```

Anything can be re-enabled one rule at a time by naming it in your own `rules` block.

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](https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint), just use QuickFix **Ignore in all files** and it will generate groovylintrc.json file.*

### Format

- **extends**: Name of a base configuration (`recommended`, `advanced`, `all`, `format`, `grails`, `tests`, `jenkinsfile`, `recommended-jenkinsfile`), or a **list** of them merged from left to right — see [Rule presets](#rule-presets)
- **rules**: List of rules definition, following format `"RuleSection.RuleName": ruleParameters` or `"RuleName": ruleParameters`
  - *RuleName*: any of the **[CodeNarc rules](https://codenarc.github.io/CodeNarc/codenarc-rule-index.html)**
  - *ruleParameters*: can be just a severity override ( `"off"`, `"error"`, `"warning"`, `"info"` ) , or a property list :
    - severity : off,error,warning,info
    - enabled : true (default) or false
    - any of the [rule advanced properties](https://codenarc.github.io/CodeNarc/codenarc-rule-index.html)

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

```json
{
    "extends": "recommended",
    "rules": {
        "comments.ClassJavadoc": "off",
        "formatting.Indentation": {
            "spacesPerIndentLevel": 4,
            "severity": "info"
        },
        "UnnecessaryReturnKeyword": "error"
    }
}
```

```json
{
    "extends": ["advanced", "jenkinsfile"],
    "rules": {
        "CouldBeElvis": "off",
        "CouldBeSwitchStatement": "off",
        "VariableName": {
            "severity": "info"
        }
    }
}
```

```json
{
    "codenarcRulesets": "RuleSet-1.groovy,RuleSet-2.groovy"
}
```

## Disabling rules in source

You can disable rules directly by adding comment in file, using [eslint style](https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments)

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

```groovy
/* groovylint-disable */

def variable = 1;

/* groovylint-enable */
```

You can also disable or enable warnings for specific rules:

```groovy
/* 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:

```groovy
/* groovylint-disable */

def variable = 1;
```

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

```groovy
/* 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:

```groovy
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:

```groovy
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:

```groovy
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](#contribute) to add more [rules](http://codenarc.github.io/CodeNarc/codenarc-rule-index.html) fixes :)

## CI/CD

### Mega-Linter

Latest npm-groovy-lint version is **natively integrated** in [**Mega-Linter**](https://nvuillam.github.io/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

```yaml
# .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

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

### Shell

Run with default settings

```shell
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:

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

Use the GitHub Container Registry image by replacing the image name:

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

### Other

You can run npm-groovy-lint using its [official Docker Hub image](https://hub.docker.com/r/nvuillam/npm-groovy-lint) or its [GHCR image](https://github.com/nvuillam/npm-groovy-lint/pkgs/container/npm-groovy-lint)

## 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

```shell
    npm install npm-groovy-lint --save
```

```javascript
    import NpmGroovyLint from "npm-groovy-lint/lib/groovy-lint.js";
    import fs from "node:fs";

    const npmGroovyLintConfig = {
        source: fs.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));
```

## Performance

npm-groovy-lint runs CodeNarc inside a local server (the "CodeNarc server") that stays alive between calls and stops itself after 1 hour idle, so only the first call pays the Java startup cost.

- **Parallel analysis**: files are split across up to 4 threads inside the server. Use `--parallelism <n>` (`-P`) to change the number of threads, or `--parallelism 1` to analyse files one at a time.
- **Result cache**: the server keeps the results of each file in memory, so re-linting a file that did not change returns instantly. The cache is only used for the default JSON output: it is skipped when CodeNarc must write a report itself (`--output` html or xml, or `--codenarcargs` reports). It is emptied when the server stops (`--killserver`), and never used with `--noserver`.
- **Memory**: the server's max heap is half the memory available (the container limit when there is one), between 2048m and 4096m. Set it yourself with `--javaoptions`, for example `--javaoptions "-Xms256m,-Xmx1024m"`.

## Troubleshooting

If you have issues with npm-groovy-lint, you can [report it on the repository](https://github.com/nvuillam/npm-groovy-lint/issues)

To help reproducing, you can access advanced logs using the NODE_DEBUG env variable

Examples:

- `NODE_DEBUG=npm-groovy-lint npm-groovy-lint ....`
- `NODE_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 run 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](https://github.com/nvuillam/npm-groovy-lint/blob/master/CONTRIBUTING.md)

## Thanks

### Other packages used

- [CodeNarc](https://github.com/CodeNarc/CodeNarc): groovy lint
- [java-caller](https://www.npmjs.com/package/java-caller): Easy call Java commands from Node
- [slf4j](http://www.slf4j.org): logging for CodeNarc
- [log4j](https://logging.apache.org/log4j/2.x/): logging for CodeNarc
- [GMetrics](https://dx42.github.io/gmetrics/): Code measures for CodeNarc
- Inspiration from [eslint](https://eslint.org/) about configuration and run patterns

### Contributors

| [<img alt="nvuillam" src="https://avatars1.githubusercontent.com/u/17500430?v=4&s=50 width=50">](https://github.com/nvuillam) | [<img alt="Dave Gallant" src="https://avatars2.githubusercontent.com/u/4519234?v=4&s=50 width=50">](https://github.com/davegallant) | [<img alt="warhod" src="https://avatars1.githubusercontent.com/u/1305176?v=4&s=50 width=50">](https://github.com/warhod) | [<img alt="pawelkopka" src="https://avatars1.githubusercontent.com/u/17784034?v=4&s=50 width=50">](https://github.com/pawelkopka) | [<img alt="docwhat" src="https://avatars1.githubusercontent.com/u/40799?v=4&s=50 width=50">](https://github.com/docwhat) | [<img alt="CatSue" src="https://avatars3.githubusercontent.com/u/26134618?v=4&s=50 width=50">](https://github.com/CatSue) |
|:-----------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------:|
|                                        [Nicolas Vuillamy](https://github.com/nvuillam)                                        |                                           [Dave Gallant](https://github.com/davegallant)                                            |                                          [Howard Lo](https://github.com/warhod)                                          |                                           [Pawel Kopka](https://github.com/pawelkopka)                                            |                                          [docwhat](https://github.com/docwhat)                                           |                                            [CatSue](https://github.com/CatSue)                                            |

## Release notes

See complete [CHANGELOG](CHANGELOG.md)

---
_Source: https://npm.io/package/npm-groovy-lint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
