npm-groovy-lint 10.0.0 → 10.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/lib/codenarc-factory.js +35 -10
- package/lib/groovy-lint.js +19 -13
- package/lib/index.js +5 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
+
## [10.0.3] 2022-08-15
|
|
6
|
+
|
|
7
|
+
- Do not output results summary in console logs when output is json or sarif
|
|
8
|
+
- Add test methods for SARIF called by CLI
|
|
9
|
+
|
|
10
|
+
## [10.0.2] 2022-08-15
|
|
11
|
+
|
|
12
|
+
- Fix error when absolute files sent as positional arguments on a linux system ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
|
13
|
+
- Improve performances by calculating the longest command directory to send as base path to CodeNarc
|
|
14
|
+
|
|
15
|
+
## [10.0.1] 2022-08-14
|
|
16
|
+
|
|
17
|
+
- Fix error when files sent as positional arguments ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
|
18
|
+
|
|
5
19
|
## [10.0.0] 2022-08-13
|
|
6
20
|
|
|
7
21
|
- Core
|
package/lib/codenarc-factory.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
const debug = require("debug")("npm-groovy-lint");
|
|
5
|
+
const commondir = require("commondir");
|
|
5
6
|
const fs = require("fs-extra");
|
|
6
7
|
const os = require("os");
|
|
7
8
|
const path = require("path");
|
|
@@ -55,8 +56,11 @@ async function prepareCodeNarcCall(options) {
|
|
|
55
56
|
|
|
56
57
|
// Define base directory
|
|
57
58
|
const baseBefore = (cnPath !== "." && cnPath.startsWith("/")) || cnPath.includes(":/") || cnPath.includes(":\\") ? "" : process.cwd() + "/";
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
const codeNarcBaseDir = positionalArgs.length > 0 ?
|
|
60
|
+
(await getCodeNarcBaseDirFromFiles(positionalArgs)) :
|
|
61
|
+
cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") :
|
|
62
|
+
process.cwd();
|
|
63
|
+
result.codeNarcBaseDir = path.resolve(codeNarcBaseDir);
|
|
60
64
|
result.codenarcArgs.push(`-basedir=${result.codeNarcBaseDir}`);
|
|
61
65
|
|
|
62
66
|
// Create ruleSet groovy file if necessary
|
|
@@ -90,16 +94,18 @@ async function prepareCodeNarcCall(options) {
|
|
|
90
94
|
if (directoryExists(resolvedPath)) {
|
|
91
95
|
finalPattern = "**/" + path.normalize(pathname.replace(/[/\\]$/u, "")).replace(/\\/gu, "/") + filePatterns;
|
|
92
96
|
}
|
|
93
|
-
//
|
|
94
|
-
if (fs.existsSync(finalPattern)) {
|
|
95
|
-
const
|
|
96
|
-
fileList.push(
|
|
97
|
+
// Relative with codeNarcBaseDir
|
|
98
|
+
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) {
|
|
99
|
+
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
100
|
+
fileList.push(absolutePath);
|
|
101
|
+
const relativePath = finalPattern.replace(/\\/gu, "/");
|
|
97
102
|
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
98
103
|
}
|
|
99
|
-
//
|
|
100
|
-
else if (fs.existsSync(
|
|
101
|
-
const
|
|
102
|
-
fileList.push(
|
|
104
|
+
// Absolute or cwd - relative path file
|
|
105
|
+
else if (fs.existsSync(finalPattern)) {
|
|
106
|
+
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
107
|
+
fileList.push(absolutePath);
|
|
108
|
+
const relativePath = path.relative(result.codeNarcBaseDir, path.resolve(finalPattern)).replace(/\\/gu, "/");
|
|
103
109
|
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
104
110
|
}
|
|
105
111
|
// Directory or ant pattern
|
|
@@ -173,6 +179,25 @@ async function prepareCodeNarcCall(options) {
|
|
|
173
179
|
return result;
|
|
174
180
|
}
|
|
175
181
|
|
|
182
|
+
// Calculate longest base dir by analyzing the list of files
|
|
183
|
+
async function getCodeNarcBaseDirFromFiles(positionalArgs) {
|
|
184
|
+
// All arguments are not files
|
|
185
|
+
if (!positionalArgs.every(fileOrDirOrPattern => fs.existsSync(fileOrDirOrPattern) || directoryExists(fileOrDirOrPattern))) {
|
|
186
|
+
return process.cwd()
|
|
187
|
+
}
|
|
188
|
+
const folders = positionalArgs.map((fileOrDir) => {
|
|
189
|
+
// Dir
|
|
190
|
+
if (directoryExists(fileOrDir)) {
|
|
191
|
+
return path.resolve(fileOrDir);
|
|
192
|
+
}
|
|
193
|
+
// File dir
|
|
194
|
+
const fileAbsolute = path.resolve(fileOrDir);
|
|
195
|
+
return path.dirname(fileAbsolute);
|
|
196
|
+
});
|
|
197
|
+
const baseDirFromFiles = commondir(folders);
|
|
198
|
+
return baseDirFromFiles
|
|
199
|
+
}
|
|
200
|
+
|
|
176
201
|
// Parse XML result file as js object
|
|
177
202
|
async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult, tmpGroovyFileName, parseErrors) {
|
|
178
203
|
if (!codeNarcJsonResult || !codeNarcJsonResult.codeNarc || !codeNarcJsonResult.packages) {
|
package/lib/groovy-lint.js
CHANGED
|
@@ -459,12 +459,12 @@ class NpmGroovyLint {
|
|
|
459
459
|
this.options.failon && this.options.failon !== "none"
|
|
460
460
|
? this.options.failon
|
|
461
461
|
: this.options.failonerror
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
462
|
+
? "error"
|
|
463
|
+
: this.options.failonwarning
|
|
464
|
+
? "warning"
|
|
465
|
+
: this.options.failoninfo
|
|
466
|
+
? "info"
|
|
467
|
+
: "none";
|
|
468
468
|
if (failureLevel === "none") {
|
|
469
469
|
return;
|
|
470
470
|
}
|
|
@@ -475,21 +475,27 @@ class NpmGroovyLint {
|
|
|
475
475
|
|
|
476
476
|
// Fail on error
|
|
477
477
|
if (failureLevel === "error" && errorNb > 0) {
|
|
478
|
-
|
|
478
|
+
if (!["json", "sarif"].includes(this.outputType)) {
|
|
479
|
+
console.error(`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found`);
|
|
480
|
+
}
|
|
479
481
|
this.status = 1;
|
|
480
482
|
}
|
|
481
483
|
// Fail on warning
|
|
482
484
|
else if (failureLevel === "warning" && (errorNb > 0 || warningNb > 0)) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
485
|
+
if (!["json", "sarif"].includes(this.outputType)) {
|
|
486
|
+
console.error(
|
|
487
|
+
`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found`
|
|
488
|
+
);
|
|
489
|
+
}
|
|
486
490
|
this.status = 1;
|
|
487
491
|
}
|
|
488
492
|
// Fail on info
|
|
489
493
|
else if (failureLevel === "info" && (errorNb > 0 || warningNb > 0 || infoNb > 0)) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
494
|
+
if (!["json", "sarif"].includes(this.outputType)) {
|
|
495
|
+
console.error(
|
|
496
|
+
`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found \n ${this.lintResult.summary.totalFoundInfoNumber} info(s) have been found`
|
|
497
|
+
);
|
|
498
|
+
}
|
|
493
499
|
this.status = 1;
|
|
494
500
|
}
|
|
495
501
|
}
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,10 @@ const linter = new NpmGroovyLint(process.argv, { origin: "index" });
|
|
|
13
13
|
process.exitCode = linter.status;
|
|
14
14
|
} catch (err) {
|
|
15
15
|
console.error("Unexpected error: " + err.message + "\n" + err.stack);
|
|
16
|
-
process.exitCode =
|
|
16
|
+
process.exitCode = 2;
|
|
17
|
+
// Quit if called by CLI and not as a module
|
|
18
|
+
if (require.main === module) {
|
|
19
|
+
process.exit();
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-groovy-lint",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.3",
|
|
4
4
|
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"axios": "^0.21.1",
|
|
50
50
|
"chalk": "^4.1.2",
|
|
51
51
|
"cli-progress": "^3.10.0",
|
|
52
|
+
"commondir": "^1.0.1",
|
|
52
53
|
"debug": "^4.1.1",
|
|
53
54
|
"decode-html": "^2.0.0",
|
|
54
55
|
"find-java-home": "^1.1.0",
|