npm-groovy-lint 10.0.3 → 11.0.0
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 +12 -0
- package/README.md +62 -46
- package/lib/codenarc-factory.js +1 -1
- package/lib/config.js +1 -1
- package/lib/groovy-lint.js +23 -3
- package/lib/options.js +1 -1
- package/lib/output.js +15 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
+
## [11.0.0] 2022-10-07
|
|
6
|
+
|
|
7
|
+
- **BREAKING CHANGE**:`--failon` is now `ìnfo` by default, meaning exit code will be `1` if there is at least an info issue found. To have previous behaviour, use `--failon none`.
|
|
8
|
+
- Display all files in console log only if `--verbose` is used ([#243](https://github.com/nvuillam/npm-groovy-lint/issues/243))
|
|
9
|
+
|
|
10
|
+
## [10.1.0] 2022-08-15
|
|
11
|
+
|
|
12
|
+
- Allow to send groovy sources as input from stdin
|
|
13
|
+
- If `--format` or `--fix` option is used when source is sent as stdin, the result is output as stdout
|
|
14
|
+
|
|
15
|
+
Example: `cat path/to/my/Jenkinsfile | npm-groovy-lint --format -`
|
|
16
|
+
|
|
5
17
|
## [10.0.3] 2022-08-15
|
|
6
18
|
|
|
7
19
|
- Do not output results summary in console logs when output is json or sarif
|
package/README.md
CHANGED
|
@@ -43,8 +43,6 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
|
|
|
43
43
|
npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
See [examples](#example-calls)
|
|
47
|
-
|
|
48
46
|
| Parameter | Type | Description |
|
|
49
47
|
|-------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
50
48
|
| -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"` |
|
|
@@ -72,6 +70,68 @@ See [examples](#example-calls)
|
|
|
72
70
|
| -p<br/> --path | String | (DEPRECATED) Directory containing the files to lint<br/> Example: `./path/to/my/groovy/files` |
|
|
73
71
|
| -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"` |
|
|
74
72
|
|
|
73
|
+
### Example calls
|
|
74
|
+
|
|
75
|
+
- Lint a file
|
|
76
|
+
|
|
77
|
+
```shell
|
|
78
|
+
npm-groovy-lint path/to/my/groovy/file.groovy
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- Lint multiple files
|
|
82
|
+
|
|
83
|
+
```shell
|
|
84
|
+
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- Lint directory
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
npm-groovy-lint path/to/my/groovy
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- Lint pattern
|
|
94
|
+
|
|
95
|
+
```shell
|
|
96
|
+
npm-groovy-lint path/to/my/groovy/*.groovy
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- Lint groovy with JSON output
|
|
100
|
+
|
|
101
|
+
```shell
|
|
102
|
+
npm-groovy-lint --output json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- Format files
|
|
106
|
+
|
|
107
|
+
```shell
|
|
108
|
+
npm-groovy-lint --format my/path/to/file.groovy my/path/to/file2.groovy
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Format and fix files
|
|
112
|
+
|
|
113
|
+
```shell
|
|
114
|
+
npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- Get formatted sources in stdout from stdin
|
|
118
|
+
|
|
119
|
+
```shell
|
|
120
|
+
cat path/to/my/Jenkinsfile | npm-groovy-lint --format -
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- Advanced config
|
|
124
|
+
|
|
125
|
+
```shell
|
|
126
|
+
npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- Lint using core CodeNarc parameters and generate HTML report file
|
|
130
|
+
|
|
131
|
+
```shell
|
|
132
|
+
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"
|
|
133
|
+
```
|
|
134
|
+
|
|
75
135
|
## Installation
|
|
76
136
|
|
|
77
137
|
```shell
|
|
@@ -145,50 +205,6 @@ OR
|
|
|
145
205
|
}
|
|
146
206
|
```
|
|
147
207
|
|
|
148
|
-
## Example calls
|
|
149
|
-
|
|
150
|
-
- Lint a file
|
|
151
|
-
|
|
152
|
-
```shell
|
|
153
|
-
npm-groovy-lint path/to/my/groovy/file.groovy
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
- Lint multiple files
|
|
157
|
-
|
|
158
|
-
```shell
|
|
159
|
-
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
- Lint directory
|
|
163
|
-
|
|
164
|
-
```shell
|
|
165
|
-
npm-groovy-lint path/to/my/groovy
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
- Lint pattern
|
|
169
|
-
|
|
170
|
-
```shell
|
|
171
|
-
npm-groovy-lint path/to/my/groovy/*.groovy
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
- Lint groovy with JSON output
|
|
175
|
-
|
|
176
|
-
```shell
|
|
177
|
-
npm-groovy-lint --output json
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
- Advanced config
|
|
181
|
-
|
|
182
|
-
```shell
|
|
183
|
-
npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
- Lint using core CodeNarc parameters and generate HTML report file
|
|
187
|
-
|
|
188
|
-
```shell
|
|
189
|
-
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html"
|
|
190
|
-
```
|
|
191
|
-
|
|
192
208
|
## Disabling rules in source
|
|
193
209
|
|
|
194
210
|
You can disable rules directly by adding comment in file, using [eslint style](https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments)
|
package/lib/codenarc-factory.js
CHANGED
|
@@ -136,7 +136,7 @@ async function prepareCodeNarcCall(options) {
|
|
|
136
136
|
// Output
|
|
137
137
|
result.output = options.output.replace(/^"(.*)"$/, "$1");
|
|
138
138
|
if (
|
|
139
|
-
["txt", "json", "sarif", "none"].includes(result.output) ||
|
|
139
|
+
["txt", "json", "sarif", "none", "stdout"].includes(result.output) ||
|
|
140
140
|
result.output.endsWith(".txt") ||
|
|
141
141
|
result.output.endsWith(".sarif") ||
|
|
142
142
|
result.output.endsWith(".json")
|
package/lib/config.js
CHANGED
|
@@ -239,7 +239,7 @@ async function loadYAMLConfigFile(filePath) {
|
|
|
239
239
|
try {
|
|
240
240
|
// empty YAML file can be null, so always use
|
|
241
241
|
const fileContent = await readFile(filePath);
|
|
242
|
-
return yaml.
|
|
242
|
+
return yaml.load(fileContent) || {};
|
|
243
243
|
} catch (e) {
|
|
244
244
|
debug(`Error reading YAML file: ${filePath}`);
|
|
245
245
|
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
|
package/lib/groovy-lint.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Imports
|
|
2
2
|
const debug = require("debug")("npm-groovy-lint");
|
|
3
|
+
const fs = require("fs-extra");
|
|
3
4
|
const os = require("os");
|
|
4
5
|
const performance = require("perf_hooks").performance;
|
|
5
6
|
|
|
@@ -137,6 +138,17 @@ class NpmGroovyLint {
|
|
|
137
138
|
this.options[configProp] = configProperties[configProp];
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
// Try to catch input from stdin. if found, use it as groovy source
|
|
142
|
+
if (this.options._ && this.options._[0] === '-') {
|
|
143
|
+
const stdInData = fs.readFileSync(0, 'utf-8');
|
|
144
|
+
this.options.source = stdInData;
|
|
145
|
+
this.options._ = [];
|
|
146
|
+
this.options.sourcefilepath = this.options.sourcefilepath || process.cwd();
|
|
147
|
+
if (this.options.format || this.options.fix) {
|
|
148
|
+
this.options.output = 'stdout';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
140
152
|
} catch (err) {
|
|
141
153
|
this.status = 2;
|
|
142
154
|
this.error = {
|
|
@@ -455,6 +467,10 @@ class NpmGroovyLint {
|
|
|
455
467
|
|
|
456
468
|
// Exit with code 1 if failon, failonerror, failonwarning or failoninfo is set
|
|
457
469
|
manageReturnCode() {
|
|
470
|
+
if (this.status > 1) {
|
|
471
|
+
// There has been a fatal error before, so there are no results
|
|
472
|
+
return ;
|
|
473
|
+
}
|
|
458
474
|
const failureLevel =
|
|
459
475
|
this.options.failon && this.options.failon !== "none"
|
|
460
476
|
? this.options.failon
|
|
@@ -468,6 +484,10 @@ class NpmGroovyLint {
|
|
|
468
484
|
if (failureLevel === "none") {
|
|
469
485
|
return;
|
|
470
486
|
}
|
|
487
|
+
if (this.lintResult.summary == null) {
|
|
488
|
+
// Special case like --codenarcargs (should not be used in thee future)
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
471
491
|
|
|
472
492
|
const errorNb = this.lintResult.summary.totalFoundErrorNumber;
|
|
473
493
|
const warningNb = this.lintResult.summary.totalFoundWarningNumber;
|
|
@@ -475,14 +495,14 @@ class NpmGroovyLint {
|
|
|
475
495
|
|
|
476
496
|
// Fail on error
|
|
477
497
|
if (failureLevel === "error" && errorNb > 0) {
|
|
478
|
-
if (!["json", "sarif"].includes(this.outputType)) {
|
|
498
|
+
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
479
499
|
console.error(`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found`);
|
|
480
500
|
}
|
|
481
501
|
this.status = 1;
|
|
482
502
|
}
|
|
483
503
|
// Fail on warning
|
|
484
504
|
else if (failureLevel === "warning" && (errorNb > 0 || warningNb > 0)) {
|
|
485
|
-
if (!["json", "sarif"].includes(this.outputType)) {
|
|
505
|
+
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
486
506
|
console.error(
|
|
487
507
|
`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found`
|
|
488
508
|
);
|
|
@@ -491,7 +511,7 @@ class NpmGroovyLint {
|
|
|
491
511
|
}
|
|
492
512
|
// Fail on info
|
|
493
513
|
else if (failureLevel === "info" && (errorNb > 0 || warningNb > 0 || infoNb > 0)) {
|
|
494
|
-
if (!["json", "sarif"].includes(this.outputType)) {
|
|
514
|
+
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
495
515
|
console.error(
|
|
496
516
|
`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
517
|
);
|
package/lib/options.js
CHANGED
|
@@ -139,7 +139,7 @@ module.exports = optionator({
|
|
|
139
139
|
option: "failon",
|
|
140
140
|
type: "String",
|
|
141
141
|
enum: ["error", "warning", "info", "none"],
|
|
142
|
-
default: "
|
|
142
|
+
default: "info",
|
|
143
143
|
description:
|
|
144
144
|
"Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Every failure level includes the more critical ones.",
|
|
145
145
|
example: ["error", "warning", "info", "none"]
|
package/lib/output.js
CHANGED
|
@@ -108,11 +108,13 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
108
108
|
// Errors
|
|
109
109
|
for (const fileNm of Object.keys(lintResult.files)) {
|
|
110
110
|
const fileErrors = lintResult.files[fileNm].errors;
|
|
111
|
-
|
|
111
|
+
let fileOutputString = c.underline(fileNm) + "\n";
|
|
112
|
+
let showFileInOutput = false ;
|
|
112
113
|
for (const err of fileErrors) {
|
|
113
114
|
if (!isErrorInLogLevelScope(err.severity, options.loglevel)) {
|
|
114
115
|
continue;
|
|
115
116
|
}
|
|
117
|
+
showFileInOutput = true ;
|
|
116
118
|
let color = "grey";
|
|
117
119
|
switch (err.severity) {
|
|
118
120
|
case "error":
|
|
@@ -135,7 +137,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
// Build error output line
|
|
138
|
-
|
|
140
|
+
fileOutputString +=
|
|
139
141
|
" " +
|
|
140
142
|
err.line.toString().padEnd(4, " ") +
|
|
141
143
|
" " +
|
|
@@ -146,7 +148,10 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
146
148
|
err.rule.padEnd(24, " ") +
|
|
147
149
|
"\n";
|
|
148
150
|
}
|
|
149
|
-
|
|
151
|
+
fileOutputString += "\n";
|
|
152
|
+
if (showFileInOutput || options.verbose) {
|
|
153
|
+
outputString += fileOutputString ;
|
|
154
|
+
}
|
|
150
155
|
}
|
|
151
156
|
outputString += "\nnpm-groovy-lint results in " + c.bold(lintResult.summary.totalFilesLinted) + " linted files:";
|
|
152
157
|
|
|
@@ -205,7 +210,9 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
205
210
|
outputString = JSON.stringify(lintResult);
|
|
206
211
|
console.log(outputString);
|
|
207
212
|
}
|
|
208
|
-
}
|
|
213
|
+
}
|
|
214
|
+
// SARIF results
|
|
215
|
+
else if (outputType === "sarif") {
|
|
209
216
|
const sarifJsonString = buildSarifResult(lintResult);
|
|
210
217
|
// SARIF file
|
|
211
218
|
if (output.endsWith(".sarif")) {
|
|
@@ -219,6 +226,10 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
219
226
|
console.log(sarifJsonString);
|
|
220
227
|
}
|
|
221
228
|
}
|
|
229
|
+
// stdout result for format / fix with source sent as stdin
|
|
230
|
+
else if (outputType === "stdout") {
|
|
231
|
+
console.log(lintResult.files[0].updatedSource);
|
|
232
|
+
}
|
|
222
233
|
return outputString;
|
|
223
234
|
}
|
|
224
235
|
|