npm-groovy-lint 11.0.0 → 11.1.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
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
+
## [11.1.0] 2022-10-31
|
|
6
|
+
|
|
7
|
+
- Provide default range when only information available is a line number ([#248](https://github.com/nvuillam/npm-groovy-lint/issues/248))
|
|
8
|
+
- New CodeNarc issues definition to calculate range in file
|
|
9
|
+
- GStringExpressionWithinString
|
|
10
|
+
- VariableName
|
|
11
|
+
|
|
5
12
|
## [11.0.0] 2022-10-07
|
|
6
13
|
|
|
7
14
|
- **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`.
|
package/lib/codenarc-factory.js
CHANGED
|
@@ -9,7 +9,7 @@ const path = require("path");
|
|
|
9
9
|
const { getConfigFileName } = require("./config.js");
|
|
10
10
|
const { collectDisabledBlocks, isFilteredError } = require("./filter.js");
|
|
11
11
|
const { getNpmGroovyLintRules } = require("./groovy-lint-rules.js");
|
|
12
|
-
const { evaluateRange, evaluateVariables, getSourceLines, normalizeNewLines } = require("./utils.js");
|
|
12
|
+
const { evaluateRange, evaluateRangeFromLine, evaluateVariables, getSourceLines, normalizeNewLines } = require("./utils.js");
|
|
13
13
|
|
|
14
14
|
////////////////////////////
|
|
15
15
|
// Build codenarc options //
|
|
@@ -325,6 +325,13 @@ async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult,
|
|
|
325
325
|
errItem.range = range;
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
+
// Add unprecise range based on line when range function has not been defined on rule
|
|
329
|
+
else if (errItem.line > 0) {
|
|
330
|
+
const range = evaluateRangeFromLine(errItem, allLines);
|
|
331
|
+
if (range && range.start.character > -1) {
|
|
332
|
+
errItem.range = range;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
328
335
|
}
|
|
329
336
|
// Add in file errors
|
|
330
337
|
files[fileNm].errors.push(errItem);
|
|
@@ -45,6 +45,32 @@ class BuildEnv implements Serializable {
|
|
|
45
45
|
}
|
|
46
46
|
`
|
|
47
47
|
}
|
|
48
|
+
],
|
|
49
|
+
rangeTests: [
|
|
50
|
+
{
|
|
51
|
+
source: `#!/usr/bin/env groovy
|
|
52
|
+
|
|
53
|
+
package org.pdxc.devops
|
|
54
|
+
|
|
55
|
+
class BuildEnv implements Serializable {
|
|
56
|
+
private String image
|
|
57
|
+
private String tag
|
|
58
|
+
private String dockerRegistry
|
|
59
|
+
private String dockerRegistryCredsId
|
|
60
|
+
private Map envVars
|
|
61
|
+
}
|
|
62
|
+
`,
|
|
63
|
+
expectedRange: {
|
|
64
|
+
start: {
|
|
65
|
+
line: 1,
|
|
66
|
+
character: 0
|
|
67
|
+
},
|
|
68
|
+
end: {
|
|
69
|
+
line: 1,
|
|
70
|
+
character: 21
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
48
74
|
]
|
|
49
75
|
};
|
|
50
76
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// GString Expression within string
|
|
2
|
+
|
|
3
|
+
const rule = {
|
|
4
|
+
rangeTests: [
|
|
5
|
+
{
|
|
6
|
+
source: `
|
|
7
|
+
def someString = '\${SCRIPT,template=\\"mail_template_robot_results.groovy\\"}'
|
|
8
|
+
`,
|
|
9
|
+
expectedRange: {
|
|
10
|
+
start: {
|
|
11
|
+
line: 2,
|
|
12
|
+
character: 0
|
|
13
|
+
},
|
|
14
|
+
end: {
|
|
15
|
+
line: 2,
|
|
16
|
+
character: 76
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { rule };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Variable name invalid
|
|
2
|
+
const { getVariableRange } = require("../utils");
|
|
3
|
+
|
|
4
|
+
const rule = {
|
|
5
|
+
variables: [
|
|
6
|
+
{
|
|
7
|
+
name: "VARIABLE_NAME",
|
|
8
|
+
regex: /Variable named (.*) in (.*) does not match the pattern (.*)/
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
range: {
|
|
12
|
+
type: "function",
|
|
13
|
+
func: (errLine, errItem, evaluatedVars) => {
|
|
14
|
+
return getVariableRange(errLine, evaluatedVars, "VARIABLE_NAME", errItem);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
rangeTests: [
|
|
18
|
+
{
|
|
19
|
+
source: `
|
|
20
|
+
def RANDOM_ID = 0
|
|
21
|
+
`,
|
|
22
|
+
expectedRange: {
|
|
23
|
+
start: {
|
|
24
|
+
line: 2,
|
|
25
|
+
character: 4
|
|
26
|
+
},
|
|
27
|
+
end: {
|
|
28
|
+
line: 2,
|
|
29
|
+
character: 13
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = { rule };
|
package/lib/utils.js
CHANGED
|
@@ -122,6 +122,11 @@ function evaluateRange(errItem, rule, evaluatedVars, errLine, allLines) {
|
|
|
122
122
|
return range;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// Get position to highlight in sources
|
|
126
|
+
function evaluateRangeFromLine(errItem, allLines) {
|
|
127
|
+
return getDefaultRange(allLines, errItem)
|
|
128
|
+
}
|
|
129
|
+
|
|
125
130
|
// Evaluate variables from messages
|
|
126
131
|
function evaluateVariables(variableDefs, msg) {
|
|
127
132
|
const evaluatedVars = [];
|
|
@@ -137,8 +142,8 @@ function evaluateVariables(variableDefs, msg) {
|
|
|
137
142
|
varDef.type && varDef.type === "number"
|
|
138
143
|
? parseInt(value, 10)
|
|
139
144
|
: varDef.type && varDef.type === "array"
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
? JSON.parse(value)
|
|
146
|
+
: value;
|
|
142
147
|
evaluatedVars.push({
|
|
143
148
|
name: varDef.name,
|
|
144
149
|
value: varValue
|
|
@@ -415,6 +420,7 @@ module.exports = {
|
|
|
415
420
|
containsOtherThan,
|
|
416
421
|
containsExceptInsideString,
|
|
417
422
|
evaluateRange,
|
|
423
|
+
evaluateRangeFromLine,
|
|
418
424
|
evaluateVariables,
|
|
419
425
|
findRangeBetweenStrings,
|
|
420
426
|
getIndentLength,
|