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 Package Compare versions

Comparing version 9.5.0 to 10.0.0

lib/java/CodeNarc-3.1.0.jar

33

CHANGELOG.md

@@ -5,4 +5,33 @@ # Changelog

- Add your updates here :)
## [10.0.0] 2022-08-13
- Core
- Upgrade to [CodeNarc v3.1.0](https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.md#version-310----jun-2022)
- 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](https://oxsecurity.github.io/megalinter/latest/) 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

@@ -12,3 +41,3 @@

## [9.4.1] 2022-01-22
## [9.4.1] 2022-01-12

@@ -15,0 +44,0 @@ - Upgrade node-sarif-builder to 2.0.1 and send npm-groovy-lint version in SARIF logs

1

lib/.groovylintrc-all.json

@@ -383,3 +383,2 @@ {

"unnecessary.UnnecessaryStringInstantiation": {},
"unnecessary.UnnecessarySubstring": {},
"unnecessary.UnnecessaryTernaryExpression": {},

@@ -386,0 +385,0 @@ "unnecessary.UnnecessaryToString": {},

@@ -32,2 +32,3 @@ {

"formatting.SpaceAfterIf": {},
"formatting.SpaceAfterMethodCallName": {},
"formatting.SpaceAfterOpeningBrace": {},

@@ -42,2 +43,3 @@ "formatting.SpaceAfterSemicolon": {},

"formatting.SpaceBeforeOpeningBrace": {},
"formatting.SpaceInsideParentheses": {},
"formatting.TrailingWhitespace": {},

@@ -44,0 +46,0 @@ "unnecessary.UnnecessaryGString": {},

@@ -42,3 +42,3 @@ // Call CodeNarc by server or java

classPath:
"java/CodeNarc-2.2.0.jar:java/groovy/lib/groovy-3.0.9.jar:java/groovy/lib/groovy-templates-3.0.9.jar:java/groovy/lib/groovy-xml-3.0.9.jar:java/groovy/lib/groovy-json-3.0.9.jar:java/groovy/lib/groovy-ant-3.0.9.jar:java/groovy/lib/ant-1.10.11.jar:java/groovy/lib/ant-launcher-1.10.11.jar:java/slf4j-api-1.7.9.jar:java/log4j-slf4j-impl-2.17.1.jar:java/log4j-api-2.17.1.jar:java/log4j-core-2.17.1.jar:java/gmetrics-1.1.jar:java/*"
"java/CodeNarc-3.1.0.jar:java/groovy/lib/groovy-3.0.9.jar:java/groovy/lib/groovy-templates-3.0.9.jar:java/groovy/lib/groovy-xml-3.0.9.jar:java/groovy/lib/groovy-json-3.0.9.jar:java/groovy/lib/groovy-ant-3.0.9.jar:java/groovy/lib/ant-1.10.11.jar:java/groovy/lib/ant-launcher-1.10.11.jar:java/slf4j-api-1.7.9.jar:java/log4j-slf4j-impl-2.18.0.jar:java/log4j-api-2.18.0.jar:java/log4j-core-2.18.0.jar:java/GMetrics-2.1.0.jar:java/*"
}

@@ -64,3 +64,6 @@ };

if (codeNarcArg.includes('="') || codeNarcArg.includes(':"')) {
codeNarcArg = codeNarcArg.replace('="', "=").replace(':"', ":");
codeNarcArg = codeNarcArg
.replace('="', "=")
.replace(':"', ":")
.replace(/ /g, "%20");
codeNarcArg = codeNarcArg.substring(0, codeNarcArg.length - 1);

@@ -81,3 +84,4 @@ }

parse: this.options.parse !== false && this.execOpts.onlyCodeNarc === false ? true : false,
file: this.execOpts.groovyFileName ? this.execOpts.groovyFileName : null,
file: this.execOpts.groovyFileName || null,
fileList: this.execOpts.inputFileList || null,
requestKey: this.execOpts.requestKey || null

@@ -84,0 +88,0 @@ },

@@ -21,2 +21,4 @@ // Shared functions

const defaultFilesPattern = ["*.groovy", "*.gvy", "Jenkinsfile", "*.gradle", "*.nf"];
// Convert NPM-groovy-lint into codeNarc arguments

@@ -29,2 +31,3 @@ // Create temporary files if necessary

let cnFiles = options.files;
const positionalArgs = options._ || [];

@@ -64,5 +67,2 @@ // If source option, create a temporary Groovy file

// Build ruleSet & file CodeNarc arguments
let defaultFilesPattern = "**/*.groovy,**/*.gvy,**/Jenkinsfile,**/*.gradle,**/*.nf";
// RuleSets codeNarc args

@@ -78,11 +78,49 @@ if (options.rulesets && options.rulesets.startsWith("{")) {

// Default file patterns
let filePatterns = defaultFilesPattern.map(filePattern => `**/${filePattern}`).join(",");
// Build codenarc arguments from eslint-like formatted positional arguments
if (positionalArgs.length > 0) {
if (options.ext && options.ext.length > 0) {
filePatterns = `/**/*.{` + options.extensions.map(ext => ext.replace(/^\./u, "")) + "}";
}
const fileList = [];
const patternsFinal = positionalArgs
.filter(Boolean)
.map(pathname => {
let finalPattern = path.normalize(pathname).replace(/\\/gu, "/");
// Directory: convert into ant pattern
const resolvedPath = path.resolve(cnPath, pathname);
if (directoryExists(resolvedPath)) {
finalPattern = "**/" + path.normalize(pathname.replace(/[/\\]$/u, "")).replace(/\\/gu, "/") + filePatterns;
}
// Absolute or cwd - relative path file
if (fs.existsSync(finalPattern)) {
const relativePath = path.relative(process.cwd(), finalPattern).replace(/\\/gu, "/");
fileList.push(relativePath);
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
}
// Relative with codeNardBaseDir
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) {
const relativePath = path.relative(process.cwd(), path.join(result.codeNarcBaseDir, finalPattern)).replace(/\\/gu, "/");
fileList.push(relativePath);
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
}
// Directory or ant pattern
return finalPattern;
})
.join(",");
result.codenarcArgs.push(`-includes="${patternsFinal}"`);
result.codeNarcIncludes = patternsFinal;
result.inputFileList = fileList;
}
// Matching files pattern(s)
if (cnFiles) {
else if (cnFiles) {
const normalizedCnFiles = cnFiles.replace(/^"(.*)"$/, "$1");
result.codenarcArgs.push(`-includes=${normalizedCnFiles}`);
result.codenarcArgs.push(`-includes="${normalizedCnFiles}"`);
result.codeNarcIncludes = normalizedCnFiles;
} else {
// If files not sent, use defaultFilesPattern, guessed from options.rulesets value
result.codenarcArgs.push(`-includes=${defaultFilesPattern}`);
result.codeNarcIncludes = defaultFilesPattern;
result.codenarcArgs.push(`-includes="${filePatterns}"`);
result.codeNarcIncludes = filePatterns;
}

@@ -92,3 +130,3 @@

if (options.ignorepattern) {
result.codenarcArgs.push(`-excludes=${options.ignorepattern}`);
result.codenarcArgs.push(`-excludes="${options.ignorepattern}"`);
result.codeNarcExcludes = options.ignorepattern;

@@ -99,9 +137,14 @@ }

result.output = options.output.replace(/^"(.*)"$/, "$1");
if (["txt", "json", "sarif", "none"].includes(result.output) ||
if (
["txt", "json", "sarif", "none"].includes(result.output) ||
result.output.endsWith(".txt") ||
result.output.endsWith(".sarif") ||
result.output.endsWith(".json")) {
result.outputType = result.output.endsWith(".txt") ? "txt"
: result.output.endsWith(".json") ? "json"
: result.output.endsWith(".sarif") ? "sarif"
result.output.endsWith(".json")
) {
result.outputType = result.output.endsWith(".txt")
? "txt"
: result.output.endsWith(".json")
? "json"
: result.output.endsWith(".sarif")
? "sarif"
: result.output;

@@ -262,3 +305,3 @@ result.codenarcArgs.push(`-report=json:stdout`);

const range = evaluateRange(errItem, errRule, evaluatedVars, errLine, allLines, { verbose: options.verbose });
if (range) {
if (range && range.start.character > -1) {
errItem.range = range;

@@ -357,2 +400,6 @@ }

const ruleDef = buildCodeNarcRule(ruleName, mergedRuleConfig);
// If rule has been sent as argument, enable it by default
if (ruleDef.enabled === false) {
ruleDef.enabled = true;
}
return ruleDef;

@@ -396,2 +443,6 @@ });

}
// Remove UnnecessarySubstring as it is no longer in CodeNarc v3
if (ruleSetJson["UnnecessarySubstring"] != null) {
delete ruleSetJson["UnnecessarySubstring"];
}
return JSON.stringify(ruleSetJson);

@@ -440,2 +491,13 @@ }

function directoryExists(resolvedPath) {
try {
return fs.statSync(resolvedPath).isDirectory();
} catch (error) {
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
return false;
}
throw error;
}
}
module.exports = { prepareCodeNarcCall, parseCodeNarcResult, manageDeleteTmpFiles };

@@ -30,3 +30,3 @@ import groovy.json.*

public TestExecutor( args2) {
public TestExecutor(args2) {
this.testExternalGlobalProps()

@@ -36,5 +36,5 @@ }

public testExternalGlobalProps() {
Utils.printlnLog( '########## testExternalGlobalProps')
Utils.printlnLog('########## testExternalGlobalProps')
def globalKeyName = new SecureRandom().with { (1..9).collect { (('a'..'z')).join()[ nextInt((('a'..'z')).join().length())] }.join() }
Utils.printlnLog( "Generated random key: ${globalKeyName}")
Utils.printlnLog("Generated random key: ${globalKeyName}")
Utils.setExternalValue(globalKeyName , 'lelama' , 'nul')

@@ -48,5 +48,5 @@ def storedValue = Utils.getExternalValue(globalKeyName , 'lelama')

assert storedValueBack == 'nul' , 'Error in global prop key storage/ retrieval (3)'
Utils.printlnLog( Utils.getExternalValue(globalKeyName))
Utils.printlnLog(Utils.getExternalValue(globalKeyName))
}
}

@@ -31,3 +31,3 @@ import groovy.io.FileType

public TestExecutor( args2) {
public TestExecutor(args2) {
this.testExternalGlobalProps()

@@ -37,5 +37,5 @@ }

public testExternalGlobalProps() {
Utils.printlnLog( '########## testExternalGlobalProps')
Utils.printlnLog('########## testExternalGlobalProps')
def globalKeyName = new Random().with { (1..9).collect { (('a'..'z')).join()[ nextInt((('a'..'z')).join().length())] }.join() }
Utils.printlnLog( "Generated random key: ${globalKeyName}")
Utils.printlnLog("Generated random key: ${globalKeyName}")
Utils.setExternalValue(globalKeyName , 'lelama' , 'nul')

@@ -49,5 +49,5 @@ def storedValue = Utils.getExternalValue(globalKeyName , 'lelama')

assert storedValueBack == 'nul' , 'Error in global prop key storage/ retrieval (3)'
Utils.printlnLog( Utils.getExternalValue(globalKeyName))
Utils.printlnLog(Utils.getExternalValue(globalKeyName))
}
}

@@ -108,2 +108,3 @@ // Additional definition for codenarc rules ( get position & available fix)

"SpaceAfterCatch",
"SpaceAfterMethodCallName",
"SpaceAfterSwitch",

@@ -118,2 +119,3 @@ "SpaceAfterWhile",

"SpaceBeforeClosingBrace",
"SpaceInsideParentheses",
"UnnecessaryDefInFieldDeclaration",

@@ -120,0 +122,0 @@ "UnnecessaryDefInMethodDeclaration",

@@ -36,2 +36,3 @@ // Imports

fileList;
inputFileList;
parseErrors = [];

@@ -233,3 +234,4 @@

codeNarcExcludes: this.codeNarcExcludes,
onlyCodeNarc: this.onlyCodeNarc
onlyCodeNarc: this.onlyCodeNarc,
inputFileList: this.inputFileList
});

@@ -236,0 +238,0 @@ if (!this.options.noserver) {

@@ -27,17 +27,7 @@ /**

{
option: "path",
alias: "p",
type: "path::String",
default: ".",
description: "Directory containing the files to lint (default: current directory)",
example: ["./path/to/my/groovy/files"]
option: "ext",
type: "[String]",
description: "Specify Groovy file extensions"
},
{
option: "files",
alias: "f",
type: "String",
description: "Comma-separated list of Ant-style file patterns specifying files that must be included",
example: ["**/Jenkinsfile", "**/*.groovy", "**/*.gradle"]
},
{
option: "source",

@@ -124,3 +114,12 @@ alias: "s",

description: "Output format (txt,json,sarif,html,xml), or path to a file with one of these extensions",
example: ["txt", "json", "sarif", "./logs/myLintResults.txt", "./logs/myLintResults.json","./logs/myLintResults.sarif", "./logs/myLintResults.html", "./logs/myLintResults.xml"]
example: [
"txt",
"json",
"sarif",
"./logs/myLintResults.txt",
"./logs/myLintResults.json",
"./logs/myLintResults.sarif",
"./logs/myLintResults.html",
"./logs/myLintResults.xml"
]
},

@@ -241,2 +240,17 @@ {

description: "Show version"
},
{
option: "path",
alias: "p",
type: "path::String",
default: ".",
description: "(DEPRECATED) Directory containing the files to lint (default: current directory)",
example: ["./path/to/my/groovy/files"]
},
{
option: "files",
alias: "f",
type: "String",
description: "(DEPRECATED) Comma-separated list of Ant-style file patterns specifying files that must be included",
example: ["**/Jenkinsfile", "**/*.groovy", "**/*.gradle"]
}

@@ -243,0 +257,0 @@ ],

@@ -253,5 +253,3 @@ // Output management

ruleId: err.rule,
fileUri: process.env.SARIF_URI_ABSOLUTE
? "file:///" + fileNm.replace(/\\/g, "/")
: path.relative(process.cwd(), fileNm)
fileUri: process.env.SARIF_URI_ABSOLUTE ? "file:///" + fileNm.replace(/\\/g, "/") : path.relative(process.cwd(), fileNm)
};

@@ -258,0 +256,0 @@ if (err && err.range && err.range.start && (err.range.start.line === 0 || err.range.start.line > 0)) {

@@ -180,3 +180,3 @@ // Unused import

`
},
} /*,
{

@@ -234,3 +234,3 @@ sourceBefore: `

`
}
} */
]

@@ -237,0 +237,0 @@ };

@@ -397,3 +397,3 @@ // Shared functions

function getNpmGroovyLintVersion(){
function getNpmGroovyLintVersion() {
let v = process.env.npm_package_version;

@@ -409,3 +409,3 @@ if (!v) {

}
return v ;
return v;
}

@@ -412,0 +412,0 @@

{
"name": "npm-groovy-lint",
"version": "9.5.0",
"version": "10.0.0",
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
"main": "index.js",
"scripts": {
"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx,json}\" --tab-width 4 --print-width 150",
"groovy:run-server-from-source": "npm run dev:kill-server && groovy -cp \"lib/java/CodeNarc-2.2.0.jar;lib/java/groovy/lib/groovy-3.0.9.jar;lib/java/groovy/lib/groovy-templates-3.0.9.jar;lib/java/groovy/lib/groovy-xml-3.0.9.jar;lib/java/groovy/lib/groovy-json-3.0.9.jar;lib/java/groovy/lib/groovy-ant-3.0.9.jar;lib/java/groovy/lib/ant-1.10.11.jar;lib/java/groovy/lib/ant-launcher-1.10.11.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.17.1.jar;lib/java/log4j-api-2.17.1.jar;lib/java/log4j-core-2.17.1.jar;lib/java/gmetrics-1.1.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx}\" --tab-width 4 --print-width 150",
"groovy:run-server-from-source": "npm run dev:kill-server && groovy -cp \"lib/java/CodeNarc-3.1.0.jar;lib/java/groovy/lib/groovy-3.0.9.jar;lib/java/groovy/lib/groovy-templates-3.0.9.jar;lib/java/groovy/lib/groovy-xml-3.0.9.jar;lib/java/groovy/lib/groovy-json-3.0.9.jar;lib/java/groovy/lib/groovy-ant-3.0.9.jar;lib/java/groovy/lib/ant-1.10.11.jar;lib/java/groovy/lib/ant-launcher-1.10.11.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.18.0.jar;lib/java/log4j-api-2.18.0.jar;lib/java/log4j-core-2.18.0.jar;lib/java/GMetrics-2.1.0.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
"groovy:build": "npm run dev:kill-server && groovyc -cp \"./lib/java*\" --encoding utf-8 ./groovy/src/main/com/nvuillam/CodeNarcServer.groovy -d ./tmp && cd ./tmp && jar -cvfm ./../lib/java/CodeNarcServer.jar ./../MANIFEST.txt ./com/nvuillam/*.class && cd ..",

@@ -61,2 +61,3 @@ "test": "npm run dev:kill-server && mocha \"test/**/*.test.js\"",

"java-caller": "^2.2.4",
"js-yaml": "^4.1.0",
"node-sarif-builder": "^2.0.1",

@@ -73,7 +74,2 @@ "optionator": "^0.8.3",

"eslint": "^8.2.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-standard": "^5.0.0",
"mocha": "^7.0.1",

@@ -80,0 +76,0 @@ "nyc": "^15.1.0",

@@ -43,9 +43,9 @@ <!-- markdownlint-disable MD013 MD033 MD034 -->

```shell
npm-groovy-lint OPTIONS
npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]
```
See [examples](#example-calls)
| Parameter | Type | Description |
|-------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -p<br/> --path | String | Directory containing the files to lint<br/> Example: `./path/to/my/groovy/files` |
| -f<br/> --files | String | 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"` |
| -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"` |

@@ -73,2 +73,4 @@ | -l<br/> --loglevel | String | Log level (error,warning or info)<br/>Default: info |

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

@@ -150,2 +152,26 @@ ## Installation

- 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

@@ -152,0 +178,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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