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 5.6.1 to 5.7.0

lib/example/test/groovy-bad.groovy

4

CHANGELOG.md
# Changelog
## [5.7.0] 2020-07-23
- [(#62)](https://github.com/nvuillam/npm-groovy-lint/pull/74) Check parse error in all files when called via CLI . Closes [#69](https://github.com/nvuillam/npm-groovy-lint/issues/69)
## [5.6.1] 2020-07-20

@@ -4,0 +8,0 @@

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

classPath:
"java/CodeNarc-1.5.jar:java/groovy/lib/groovy-3.0.3.jar:java/groovy/lib/groovy-templates-3.0.3.jar:java/groovy/lib/groovy-xml-3.0.3.jar:java/groovy/lib/groovy-json-3.0.3.jar:java/slf4j-api-1.7.9.jar:java/log4j-slf4j-impl-2.13.0.jar:java/log4j-api-2.13.0.jar:java/log4j-core-2.13.0.jar:java/GMetrics-0.7.jar:java/*"
"java/CodeNarc-1.5.jar:java/groovy/lib/groovy-3.0.3.jar:java/groovy/lib/groovy-templates-3.0.3.jar:java/groovy/lib/groovy-xml-3.0.3.jar:java/groovy/lib/groovy-json-3.0.3.jar:java/groovy/lib/groovy-ant-3.0.3.jar:java/groovy/lib/ant-1.10.7.jar:java/groovy/lib/ant-launcher-1.10.7.jar:java/slf4j-api-1.7.9.jar:java/log4j-slf4j-impl-2.13.0.jar:java/log4j-api-2.13.0.jar:java/log4j-core-2.13.0.jar:java/GMetrics-0.7.jar:java/*"
}

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

codeNarcArgs: codeNarcArgsString,
parse: this.options.parse ? true : false,
codeNarcBaseDir: this.execOpts.codeNarcBaseDir,
codeNarcIncludes: this.execOpts.codeNarcIncludes,
codeNarcExcludes: this.execOpts.codeNarcExcludes,
parse: this.options.parse !== false && this.execOpts.onlyCodeNarc === false ? true : false,
file: this.execOpts.groovyFileName ? this.execOpts.groovyFileName : null,

@@ -103,6 +106,18 @@ requestKey: this.execOpts.requestKey || null

} else {
console.error("CodeNarcServer unexpected error:\n" + JSON.stringify(e, null, 2));
console.error(
"CodeNarcServer unexpected error:\n" +
JSON.stringify(e, null, 2) +
"\n" +
(e.response && e.response.data && e.response.data.errorDtl ? JSON.stringify(e.response.data.errorDtl, null, 2) : undefined)
);
}
this.serverStatus = "error";
return { status: 2, error: { msg: e.message, stack: e.stack } };
return {
status: 2,
error: {
msg: e.message,
stack: e.stack,
responseData: e.response && e.response.data && e.response.data.errorDtl ? e.response.data.errorDtl : undefined
}
};
}

@@ -109,0 +124,0 @@

83

lib/codenarc-factory.js

@@ -76,6 +76,9 @@ // Shared functions

if (cnFiles) {
result.codenarcArgs.push(`-includes=${cnFiles.replace(/^"(.*)"$/, "$1")}`);
const normalizedCnFiles = cnFiles.replace(/^"(.*)"$/, "$1");
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;
}

@@ -86,2 +89,3 @@

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

@@ -156,2 +160,42 @@

let errId = 0;
// Manage parse errors (returned by CodeNarcServer, not CodeNarc)
if (parseErrors && Object.keys(parseErrors).length > 0) {
for (const fileNm1 of Object.keys(parseErrors)) {
const fileParseErrors = parseErrors[fileNm1];
const fileNm = options.source ? 0 : path.resolve(fileNm1);
if (files[fileNm] == null) {
files[fileNm] = { errors: [] };
}
for (const parseError of fileParseErrors) {
// Convert GroovyShell.parse Compilation exception error into NpmGroovyLint exception
let msg =
parseError.cause && parseError.cause.message ? parseError.cause.message : `Unknown parsing error: ${JSON.stringify(parseError)}`;
// Remove 'unable to resolve class' error as GroovyShell.parse is called without ClassPath
if (msg.startsWith("unable to resolve class ")) {
continue;
}
// Create new error
const errItemParse = {
id: errId,
line: parseError.cause && parseError.cause.line ? parseError.cause.line : 0,
rule: "NglParseError",
severity: "error",
msg: msg
};
// Add range if provided
if (parseError.cause && parseError.cause.startColumn) {
errItemParse.range = {
start: { line: parseError.cause.startLine, character: parseError.cause.startColumn },
end: { line: parseError.cause.endLine, character: parseError.cause.endColumn }
};
}
files[fileNm].errors.push(errItemParse);
errId++;
}
}
}
// Extract CodeNarc reported errors
for (const folderInfo of tempXmlFileContent.CodeNarc.Package) {

@@ -164,3 +208,5 @@ if (!folderInfo.File) {

// Build file name, or use '0' if source has been sent as input parameter
const fileNm = options.source ? 0 : codeNarcBaseDir + "/" + (folderInfo["$"].path ? folderInfo["$"].path + "/" : "") + fileInfo["$"].name;
const fileNm = options.source
? 0
: path.resolve(codeNarcBaseDir + "/" + (folderInfo["$"].path ? folderInfo["$"].path + "/" : "") + fileInfo["$"].name);
if (files[fileNm] == null) {

@@ -176,35 +222,2 @@ files[fileNm] = { errors: [] };

// Manage parse error ( returned by CodeNarcServer, not CodeNarc)
if (parseErrors && parseErrors.length > 0) {
for (const parseError of parseErrors) {
// Convert GroovyShell.parse Compilation exception error into NpmGroovyLint exception
let msg =
parseError.cause && parseError.cause.message
? parseError.cause.message
: `Unknown parsing error: ${JSON.stringify(parseError)}`;
// Remove 'unable to resolve class' error as GroovyShell.parse is called without ClassPath
if (msg.startsWith("unable to resolve class ")) {
continue;
}
// Create new error
const errItemParse = {
id: errId,
line: parseError.cause && parseError.cause.line ? parseError.cause.line : 0,
rule: "NglParseError",
severity: "error",
msg: msg
};
// Add range if provided
if (parseError.cause && parseError.cause.startColumn) {
errItemParse.range = {
start: { line: parseError.cause.startLine, character: parseError.cause.startColumn },
end: { line: parseError.cause.endLine, character: parseError.cause.endColumn }
};
}
files[fileNm].errors.push(errItemParse);
errId++;
}
}
// Browse CodeNarc XML file reported errors

@@ -211,0 +224,0 @@ for (const violation of fileInfo.Violation) {

@@ -33,2 +33,4 @@ #! /usr/bin/env node

codeNarcBaseDir;
codeNarcIncludes;
codeNarcExcludes;
codeNarcStdOut;

@@ -223,3 +225,7 @@ codeNarcStdErr;

groovyFileName: this.tmpGroovyFileName ? this.tmpGroovyFileName : null,
requestKey: this.requestKey || null
requestKey: this.requestKey || null,
codeNarcBaseDir: this.codeNarcBaseDir,
codeNarcIncludes: this.codeNarcIncludes,
codeNarcExcludes: this.codeNarcExcludes,
onlyCodeNarc: this.onlyCodeNarc
});

@@ -226,0 +232,0 @@ if (!this.options.noserver) {

@@ -58,4 +58,3 @@ /**

type: "Boolean",
dependsOn: ["and", "source", "sourcefilepath"],
description: "Try to compile the source code and return parse errors (works only with source argument)"
description: "Try to parse the source code with GroovyShell and return errors (use argument --no-parse if you want to deactivate)"
},

@@ -62,0 +61,0 @@ {

@@ -65,2 +65,16 @@ #! /usr/bin/env node

});
it("(API:source) should detect and display a parse error", async () => {
const npmGroovyLintConfig = {
failon: "error",
path: "./lib/example/test",
files: "**/groovy-bad.groovy",
insight: false,
output: "txt"
};
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
assert(linter.status === 1, `Linter status is 1 (${linter.status} returned)`);
assert(linter.outputString.includes("NglParseError"), "Parse error has been detected");
});
});

@@ -127,3 +127,3 @@ #! /usr/bin/env node

assert(
linter.outputString.includes(`npm-groovy-lint results in ${c.bold(8)} linted files`),
linter.outputString.includes(`npm-groovy-lint results in ${c.bold(9)} linted files`),
"Number of linted files is displayed in summary"

@@ -183,3 +183,2 @@ );

output: "txt",
parse: true,
insight: false,

@@ -191,2 +190,3 @@ verbose: true

assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
assert(linter.outputString.includes("NglParseError"), "Parse error has been detected");
checkCodeNarcCallsCounter(1);

@@ -193,0 +193,0 @@ });

@@ -42,3 +42,3 @@ #! /usr/bin/env node

assert(!stdout.includes(`ToIgnore.groovy`), `ToIgnore.groovy has been ignored \n${stdout}`);
assert(stdout.includes(`npm-groovy-lint results in ${c.bold(8)} linted files`), `Number of linted files is displayed in summary \n${stdout}`);
assert(stdout.includes(`npm-groovy-lint results in ${c.bold(9)} linted files`), `Number of linted files is displayed in summary \n${stdout}`);
});

@@ -45,0 +45,0 @@

{
"name": "npm-groovy-lint",
"version": "5.6.1",
"version": "5.7.0",
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",

@@ -8,3 +8,3 @@ "main": "index.js",

"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx,json}\" --tab-width 4 --print-width 150",
"groovy:run-server-from-source": "groovy -cp \"lib/java/CodeNarc-1.5.jar;lib/java/groovy/lib/groovy-3.0.3.jar;lib/java/groovy/lib/groovy-templates-3.0.3.jar;lib/java/groovy/lib/groovy-xml-3.0.3.jar;lib/java/groovy/lib/groovy-json-3.0.3.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.13.0.jar;lib/java/log4j-api-2.13.0.jar;lib/java/log4j-core-2.13.0.jar;lib/java/GMetrics-0.7.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
"groovy:run-server-from-source": "groovy -cp \"lib/java/CodeNarc-1.5.jar;lib/java/groovy/lib/groovy-3.0.3.jar;lib/java/groovy/lib/groovy-templates-3.0.3.jar;lib/java/groovy/lib/groovy-xml-3.0.3.jar;lib/java/groovy/lib/groovy-json-3.0.3.jar;lib/java/groovy/lib/groovy-ant-3.0.3.jar;lib/java/groovy/lib/ant-1.10.7.jar;lib/java/groovy/lib/ant-launcher-1.10.7.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.13.0.jar;lib/java/log4j-api-2.13.0.jar;lib/java/log4j-core-2.13.0.jar;lib/java/GMetrics-0.7.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
"groovy:build": "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 ..",

@@ -11,0 +11,0 @@ "test": "mocha \"lib/test/**/*.test.js\"",

@@ -10,2 +10,4 @@ # NPM GROOVY LINT (+ Format & Auto-fix)

[![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)

@@ -20,7 +22,6 @@ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

- Use option **--fix** to activate autofixing of fixable rules (beta)
- Use option **--parse** to also detect future compilation errors
Easy to integrate in a CD/CI 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)
You can also use this package in [Visual Studio Code Groovy Lint extension](https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint) and [Docker Image](#CALL-VIA-DOCKER)

@@ -55,3 +56,3 @@ ![https://github.com/nvuillam/npm-groovy-lint/raw/master/doc/images/npm-groovy-lint-results.png](https://github.com/nvuillam/npm-groovy-lint/raw/master/doc/images/npm-groovy-lint-results.png)

| -c<br/> --config | String | Custom path to [GroovyLint config file](#Configuration), or preset config `recommended|recommended-jenkinsfile|all`<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 (works only with source argument) |
| --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 | (beta) Format source code |

@@ -376,2 +377,6 @@ | --fix | Boolean | (beta) Automatically fix problems when possible<br/> See [Autofixable rules](#Autofixable-rules) |

### [5.7.0] 2020-07-23
- [(#62)](https://github.com/nvuillam/npm-groovy-lint/pull/74) Check parse error in all files when called via CLI . Closes [#69](https://github.com/nvuillam/npm-groovy-lint/issues/69)
### [5.6.1] 2020-07-20

@@ -378,0 +383,0 @@

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