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
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 :
See CHANGELOG
Any question, problem or enhancement request ? Ask here :)
npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]Parameter Type Description -o
txt
"txt"
"json"
"./logs/myLintResults.txt"
"./logs/myLintResults.sarif"
"./logs/myLintResults.html"
"./logs/myLintResults.xml"
recommended|recommended-jenkinsfile|all
.groovylintrc.json|js|yml|package.json
config file, or default npm-groovy-lint config if not defined.
"SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"
"Indentation"
"./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
replaceConfig
(default), appendConfig
-s
"**/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
--insight
option. --codenarcargs String Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored)
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml
-h
./path/to/my/groovy/files
-f
"**/*.groovy,**/Jenkinsfile,**/*.gradle"
"**/Jenkinsfile"
"**/*.groovy"
"**/*.gradle"
"**/mySingleFile.groovy"
npm-groovy-lint path/to/my/groovy/file.groovy
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
npm-groovy-lint path/to/my/groovy
npm-groovy-lint path/to/my/groovy/*.groovy
npm-groovy-lint --output json
npm-groovy-lint --format my/path/to/file.groovy my/path/to/file2.groovy
npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy
cat path/to/my/Jenkinsfile | npm-groovy-lint --format -
npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"
npm install -g npm-groovy-lint
npm install -g npm-groovy-lint@8.2.0
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
If you are using VsCode Groovy Lint extension, just use QuickFix Ignore in all files and it will generate groovylintrc.json file.
recommended
, recommended-jenkinsfile
, all
)"RuleSection.RuleName": ruleParameters
or "RuleName": ruleParameters
"off"
, "error"
, "warning"
, "info"
) , or a property list :
OR
.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){ "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;
Contribute to add more rules fixes :)
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/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
node { checkout scm docker.image('nvuillam/npm-groovy-lint').inside { sh 'npm-groovy-lint' } }
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
You can run npm-groovy-lint using its official docker image
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));
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.
Contributions are very welcome !
Please follow Contribution instructions
See complete CHANGELOG
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4