Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-groovy-lint

Package Overview
Dependencies
Maintainers
1
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-groovy-lint

NPM CodeNarc wrapper to easily lint Groovy files

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.6K
decreased by-37.28%
Maintainers
1
Weekly downloads
 
Created
Source

NPM GROOVY LINT (and FIX !)

Version Downloads/week Downloads/total CircleCI codecov GitHub contributors GitHub stars License HitCount PRs Welcome Say Thanks!

Groovy / Jenkinsfile linter and autofixer

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

Use option --fix to activate autofixing (the function is still in experimental phase, you may have to run it several times at first so CodeNarc take in account the updates)

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

https://github.com/nvuillam/npm-groovy-lint/raw/master/doc/images/npm-groovy-lint-results.png

See CHANGELOG

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

INSTALLATION

    $ npm install -g npm-groovy-lint

USAGE

    $ npm-groovy-lint OPTIONS
ParameterTypeDescription
-p
--path
StringDirectory containing the files to lint
Example: ./path/to/my/groovy/files
-f
--files
StringComma-separated list of Ant-style file patterns specifying files that must be included.
Default: "**/*.groovy,**/Jenkinsfile"
Examples:
- "**/Jenkinsfile"
- "**/*.groovy"
-o
--output
StringOutput format (txt,json,html,xml), or path to a file with one of these extensions
Default: txt
Examples:
- "txt"
- "json"
- "./logs/myLintResults.txt"
- "./logs/myLintResults.json"
- "./logs/myLintResults.html"
- "./logs/myLintResults.xml"
-l
--loglevel
StringLog level (error,warning or info)
Default: info
-c
--config
StringCustom path to GroovyLint config file
Default: Browse current directory to find groovylintrc.js/json/yml/package.json config file, or default npm-groovy-lint config if not defined.
Note: command-line arguments have priority on config file properties
-r
--rulesets
StringRuleSet 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"
- EmptyInstanceInitializer,EmptySwitchStatement,ForLoopShouldBeWhileLoop
-s
--source
StringIf path and files are not set, you can directly send the source code string to analyze
-v
--verbose
BooleanMore outputs in console, including performed fixes
--fixBoolean(Experimental) Automatically fix problems when possible
See Autofixable rules
-i
--ignorepattern
StringComma-separated list of Ant-style file patterns specifying files that must be ignored
Default: none
Example: "**/test/*""
--failonerrorBooleanFails if at least one error is found
--failonwarningBooleanFails if at least one warning is found
--noserverBooleannpm-groovy-lint launches a microservice to avoid performance issues caused by loading jaja/groovy everytime,that auto kills itself after 1h idle. Use this argument if you do not want to use this feature
--failoninfoBooleanFails if at least one error is found
--codenarcargsBooleanUse 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="jdeploy-bundle/lib/example" -rulesetfiles="file:jdeploy-bundle/lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml
-h
--help
BooleanShow help (npm-groovy-lint -h OPTIONNAME to see option detail with examples)

CONFIGURATION

Define a file named .groovylintrc.js (or .json or .YAML, or include in a property groovyLintConfig in package.json)

Format :

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

Example:

module.exports = {
    extends: "recommended",
    rules: {
        "comments.ClassJavadoc": 'off',
        "formatting.Indentation": {
            spacesPerIndentLevel: 4,
            severity: "info"
        },
        'unnecessary.UnnecessaryReturnKeyword': "error"
    }
}

EXAMPLES

  • Lint groovy with JSON output
    $ npm-groovy-lint --output json
  • 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="jdeploy-bundle/lib/example" -rulesetfiles="file:jdeploy-bundle/lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"

Autofixable rules (experimental)

  • ConsecutiveBlankLines
  • FileEndsWithoutNewline
  • IfStatementBraces
  • Indentation (IfStatementBraces and ElsefStatementBraces must be manually fixed to have correct indentation)
  • NoTabCharacter
  • SpaceAfterCatch
  • SpaceAfterComma
  • SpaceAfterOpeningBrace
  • SpaceAroundOperator
  • SpaceBeforeOpeningBrace
  • TrailingWhitespace
  • UnnecessaryDefInFieldDeclaration
  • UnnecessaryGroovyImport
  • UnnecessaryGString
  • UnnecessarySemicolon
  • UnnecessaryToString
  • UnusedImport

Contribute to add more rules fixes :)

Call via JS 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/jdeploy-bundle/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

  • Embedded Groovy 3.0.2 may have issues with JDK12, please use JDK11 or a precedent version if possible
  • CodeNarc server does not seems to Work on some Linux environments (java classes are loaded at each npm-groovy-lint call so performances are slower)
  • On some environments, it has been observed that installed Groovy version must match Groovy embedded jars delivered with npm-groovy-lint (3.0.2)

CONTRIBUTE

Contributions are very welcome !

  • Fork the repo and clone it on your computer
  • Run npm run lint then npm run test to check your updates didn't break anything
  • Once your code is ready, documented and testing, please make a pull request :)

THANKS

This package uses :

Keywords

FAQs

Package last updated on 15 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc