npm-groovy-lint

raw JSON →
17.0.4 verified Fri May 01 auth: no javascript

Lint, format, and auto-fix Groovy, Jenkinsfile, and Gradle files. Current stable version 17.0.4 (released Dec 2024). Based on CodeNarc, it provides out-of-the-box linting with over 300 rules, formatting (--format), and auto-fixing (--fix). Unlike the Groovy compiler or code-narc CLI, it integrates directly into Node.js workflows, CI/CD pipelines, and editor extensions (VS Code). Ships TypeScript types. Release cadence is irregular with multiple patches per year. Requires Node >= 22.0.0 and Java (17-24) for CodeNarc.

error Error: Cannot find module 'npm-groovy-lint'
cause Package not installed or import path incorrect.
fix
Run npm install npm-groovy-lint and ensure using ESM import (e.g., import { NpmGroovyLint } from 'npm-groovy-lint').
error TypeError: (0 , _npmGroovyLint.NpmGroovyLint) is not a constructor
cause Using CommonJS require or incorrect import syntax.
fix
Change to import { NpmGroovyLint } from 'npm-groovy-lint' (ESM) or const { NpmGroovyLint } = await import('npm-groovy-lint').
error java.lang.NoClassDefFoundError: org/codehaus/groovy/control/MultipleCompilationErrorsException
cause Missing or incompatible Java version.
fix
Install Java 17-24 and set JAVA_HOME. Verify with java -version.
breaking Dropped support for Node < 22; v17 requires Node >= 22.
fix Upgrade Node.js to version 22 or later.
deprecated CommonJS require style no longer works; package is ESM-only since v17.
fix Use import statements; ensure package.json has "type": "module".
gotcha Java must be installed (Java 17-24); CodeNarc runs on JVM.
fix Install Java runtime and set JAVA_HOME if not already set.
breaking CodeNarc upgrade to 3.7.0 in v16 may change rule behavior.
fix Review rule configurations; run with --verbose to see rule changes.
gotcha Autofix may produce invalid code in some cases (e.g., Spock data providers).
fix Review fixed output manually; upgrade to v15.2.2+ for partial fixes.
gotcha Docker images now available on ghcr.io; older Docker Hub tags may not be updated.
fix Pull from ghcr.io/nvuillam/npm-groovy-lint instead of Docker Hub.
npm install npm-groovy-lint
yarn add npm-groovy-lint
pnpm add npm-groovy-lint

Demonstrates linting a Groovy source string with auto-fix and formatting enabled.

import { NpmGroovyLint } from 'npm-groovy-lint';

const linter = new NpmGroovyLint({
  source: 'def x = 1',
  fix: true,
  format: true,
  rulesets: ['/path/to/ruleset.groovy'],
});

const result = await linter.run();
console.log(JSON.stringify(result, null, 2));
// Expected output contains lintResult.files[0].errors and warnings