npm-groovy-lint 8.2.0 → 9.3.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 +24 -1
- package/README.md +8 -5
- package/lib/.groovylintrc-all.json +6 -0
- package/lib/codenarc-caller.js +16 -8
- package/lib/config.js +2 -2
- package/lib/example/RuleSet-All.groovy +417 -409
- package/lib/example/SampleFile.groovy +0 -8
- package/lib/example/SampleFileSmall.groovy +0 -6
- package/lib/example/SampleFileSmallFixed.txt +0 -5
- package/lib/example/SampleFileSmallFormatted.txt +0 -6
- package/lib/groovy-lint-fix.js +0 -2
- package/lib/groovy-lint.js +0 -2
- package/lib/java/CodeNarc-2.2.0.jar +0 -0
- package/lib/java/CodeNarcServer.jar +0 -0
- package/lib/java/groovy/lib/{ant-1.10.8.jar → ant-1.10.11.jar} +0 -0
- package/lib/java/groovy/lib/ant-launcher-1.10.11.jar +0 -0
- package/lib/java/groovy/lib/{groovy-3.0.5.jar → groovy-3.0.9.jar} +0 -0
- package/lib/java/groovy/lib/{groovy-ant-3.0.5.jar → groovy-ant-3.0.9.jar} +0 -0
- package/lib/java/groovy/lib/{groovy-json-3.0.5.jar → groovy-json-3.0.9.jar} +0 -0
- package/lib/java/groovy/lib/{groovy-templates-3.0.5.jar → groovy-templates-3.0.9.jar} +0 -0
- package/lib/java/groovy/lib/{groovy-xml-3.0.5.jar → groovy-xml-3.0.9.jar} +0 -0
- package/lib/java/log4j-api-2.17.1.jar +0 -0
- package/lib/java/log4j-core-2.17.1.jar +0 -0
- package/lib/java/log4j-slf4j-impl-2.17.1.jar +0 -0
- package/package.json +16 -14
- package/lib/java/CodeNarc-2.0.0.jar +0 -0
- package/lib/java/groovy/lib/ant-launcher-1.10.8.jar +0 -0
- package/lib/java/log4j-api-2.13.0.jar +0 -0
- package/lib/java/log4j-core-2.13.0.jar +0 -0
- package/lib/java/log4j-slf4j-impl-2.13.0.jar +0 -0
- package/lib/test/errors.test.js +0 -92
- package/lib/test/helpers/common.js +0 -84
- package/lib/test/helpers/init.js +0 -29
- package/lib/test/lint-api.test.js +0 -221
- package/lib/test/lint-build-fix.test.js +0 -43
- package/lib/test/lint-build-format.test.js +0 -43
- package/lib/test/lint-build.test.js +0 -168
- package/lib/test/lint-comments.test.js +0 -197
- package/lib/test/lint-fix.rules.test.js +0 -71
- package/lib/test/lint-fix.test.js +0 -224
- package/lib/test/lint-format.test.js +0 -293
- package/lib/test/miscellaneous.test.js +0 -326
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const NpmGroovyLint = require("../groovy-lint.js");
|
|
4
|
-
let assert = require("assert");
|
|
5
|
-
const fse = require("fs-extra");
|
|
6
|
-
const rimraf = require("rimraf");
|
|
7
|
-
const {
|
|
8
|
-
beforeEachTestCase,
|
|
9
|
-
copyFilesInTmpDir,
|
|
10
|
-
checkCodeNarcCallsCounter,
|
|
11
|
-
SAMPLE_FILE_BIG_PATH,
|
|
12
|
-
SAMPLE_FILE_SMALL_PATH
|
|
13
|
-
} = require("./helpers/common");
|
|
14
|
-
|
|
15
|
-
describe("Lint & fix with API", function() {
|
|
16
|
-
beforeEach(beforeEachTestCase);
|
|
17
|
-
|
|
18
|
-
it("(API:source) should lint then fix only a list of errors", async () => {
|
|
19
|
-
const sampleFilePath = SAMPLE_FILE_BIG_PATH;
|
|
20
|
-
const prevFileContent = fse.readFileSync(sampleFilePath).toString();
|
|
21
|
-
const npmGroovyLintConfig = {
|
|
22
|
-
source: prevFileContent,
|
|
23
|
-
sourcefilepath: sampleFilePath,
|
|
24
|
-
nolintafter: true,
|
|
25
|
-
output: "none",
|
|
26
|
-
insight: false,
|
|
27
|
-
verbose: true
|
|
28
|
-
};
|
|
29
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
30
|
-
|
|
31
|
-
let errIdList = linter.lintResult.files[0].errors.filter(error => error.fixable === true).map(err => err.id);
|
|
32
|
-
errIdList = errIdList.slice(0, 500);
|
|
33
|
-
await linter.fixErrors(errIdList);
|
|
34
|
-
|
|
35
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
36
|
-
assert(linter.lintResult.summary.totalFixedNumber >= 100, "Errors have been fixed"); // can be more than the five sent errors, as there are other triggered fixes
|
|
37
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
38
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
39
|
-
checkCodeNarcCallsCounter(2);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("(API:source) should lint and fix (one shot)", async () => {
|
|
43
|
-
const sampleFilePath = SAMPLE_FILE_BIG_PATH;
|
|
44
|
-
const expectedFixedErrs = 995;
|
|
45
|
-
const prevFileContent = fse.readFileSync(sampleFilePath).toString();
|
|
46
|
-
const npmGroovyLintConfig = {
|
|
47
|
-
source: prevFileContent,
|
|
48
|
-
sourcefilepath: sampleFilePath,
|
|
49
|
-
fix: true,
|
|
50
|
-
output: "txt",
|
|
51
|
-
insight: false,
|
|
52
|
-
verbose: true
|
|
53
|
-
};
|
|
54
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
55
|
-
|
|
56
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
57
|
-
assert(
|
|
58
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
59
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
60
|
-
);
|
|
61
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
62
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
63
|
-
checkCodeNarcCallsCounter(3);
|
|
64
|
-
}).timeout(200000);
|
|
65
|
-
|
|
66
|
-
it("(API:source) should lint and fix (no lintagainafterfix)", async () => {
|
|
67
|
-
const sampleFilePath = SAMPLE_FILE_BIG_PATH;
|
|
68
|
-
const expectedFixedErrs = 995;
|
|
69
|
-
const prevFileContent = fse.readFileSync(sampleFilePath).toString();
|
|
70
|
-
const npmGroovyLintConfig = {
|
|
71
|
-
source: prevFileContent,
|
|
72
|
-
sourcefilepath: sampleFilePath,
|
|
73
|
-
fix: true,
|
|
74
|
-
nolintafter: true,
|
|
75
|
-
output: "txt",
|
|
76
|
-
insight: false,
|
|
77
|
-
verbose: true
|
|
78
|
-
};
|
|
79
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
80
|
-
|
|
81
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
82
|
-
assert(
|
|
83
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
84
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
85
|
-
);
|
|
86
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
87
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
88
|
-
checkCodeNarcCallsCounter(2);
|
|
89
|
-
}).timeout(200000);
|
|
90
|
-
|
|
91
|
-
it("(API:source) should lint and fix (no lintagainafterfix) 2", async () => {
|
|
92
|
-
const sampleFilePath = SAMPLE_FILE_SMALL_PATH;
|
|
93
|
-
const expectedFixedErrs = 14;
|
|
94
|
-
const prevFileContent = fse.readFileSync(sampleFilePath).toString();
|
|
95
|
-
const npmGroovyLintConfig = {
|
|
96
|
-
source: prevFileContent,
|
|
97
|
-
sourcefilepath: sampleFilePath,
|
|
98
|
-
fix: true,
|
|
99
|
-
nolintafter: true,
|
|
100
|
-
output: "txt",
|
|
101
|
-
insight: false,
|
|
102
|
-
verbose: true
|
|
103
|
-
};
|
|
104
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
105
|
-
|
|
106
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
107
|
-
assert(
|
|
108
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
109
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
110
|
-
);
|
|
111
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
112
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
113
|
-
checkCodeNarcCallsCounter(1);
|
|
114
|
-
}).timeout(200000);
|
|
115
|
-
|
|
116
|
-
it("(API:file) should lint and fix a Jenkinsfile in one shot", async function() {
|
|
117
|
-
const tmpDir = await copyFilesInTmpDir();
|
|
118
|
-
const prevFileContent = fse.readFileSync(tmpDir + "/Jenkinsfile").toString();
|
|
119
|
-
const linter = await new NpmGroovyLint(
|
|
120
|
-
[
|
|
121
|
-
process.execPath,
|
|
122
|
-
"",
|
|
123
|
-
"--output",
|
|
124
|
-
'"npm-groovy-fix-log.json"',
|
|
125
|
-
"--path",
|
|
126
|
-
'"' + tmpDir + '"',
|
|
127
|
-
"--files",
|
|
128
|
-
"**/Jenkinsfile",
|
|
129
|
-
"--nolintafter",
|
|
130
|
-
"--fix",
|
|
131
|
-
"--no-insight",
|
|
132
|
-
"--verbose"
|
|
133
|
-
],
|
|
134
|
-
{}
|
|
135
|
-
).run();
|
|
136
|
-
|
|
137
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
138
|
-
assert(linter.lintResult.summary.totalFixedNumber > 0, "Error have been fixed");
|
|
139
|
-
assert(linter.lintResult.files[Object.keys(linter.lintResult.files)[0]].updatedSource !== prevFileContent, "File content has been updated");
|
|
140
|
-
assert(fse.existsSync("npm-groovy-fix-log.json"), "Output json file has been produced");
|
|
141
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
142
|
-
|
|
143
|
-
fse.removeSync("npm-groovy-fix-log.json");
|
|
144
|
-
rimraf.sync(tmpDir);
|
|
145
|
-
checkCodeNarcCallsCounter(2);
|
|
146
|
-
}).timeout(120000);
|
|
147
|
-
|
|
148
|
-
it("(API:file) should fix only some errors", async function() {
|
|
149
|
-
const fixRules = [
|
|
150
|
-
// Line rules or not changing line rules
|
|
151
|
-
|
|
152
|
-
"Indentation", // ok
|
|
153
|
-
// "UnnecessaryGString",
|
|
154
|
-
// "SpaceBeforeOpeningBrace",
|
|
155
|
-
// "SpaceAfterOpeningBrace",
|
|
156
|
-
// "SpaceAfterCatch",
|
|
157
|
-
// "SpaceAroundOperator",
|
|
158
|
-
// "SpaceAfterComma",
|
|
159
|
-
// "UnnecessaryDefInFieldDeclaration",
|
|
160
|
-
"UnnecessarySemicolon"
|
|
161
|
-
// "IfStatementBraces",
|
|
162
|
-
// "ElseStatementBraces",
|
|
163
|
-
// "ConsecutiveBlankLines",
|
|
164
|
-
// "IndentationClosingBraces",
|
|
165
|
-
// "IndentationComments",
|
|
166
|
-
// "FileEndsWithoutNewline" // ok
|
|
167
|
-
];
|
|
168
|
-
const tmpDir = await copyFilesInTmpDir();
|
|
169
|
-
const linter = await new NpmGroovyLint(
|
|
170
|
-
[
|
|
171
|
-
process.execPath,
|
|
172
|
-
"",
|
|
173
|
-
"--path",
|
|
174
|
-
'"' + tmpDir + '"',
|
|
175
|
-
"--fix",
|
|
176
|
-
"--fixrules",
|
|
177
|
-
fixRules.join(","),
|
|
178
|
-
"--nolintafter",
|
|
179
|
-
"--output",
|
|
180
|
-
'"npm-groovy-fix-log-should-fix-only-some-errors.txt"',
|
|
181
|
-
"--no-insight",
|
|
182
|
-
"--verbose"
|
|
183
|
-
],
|
|
184
|
-
{}
|
|
185
|
-
).run();
|
|
186
|
-
|
|
187
|
-
assert(linter.status === 0);
|
|
188
|
-
assert(linter.lintResult.summary.totalFixedNumber > 0, "Errors have been fixed");
|
|
189
|
-
assert(fse.existsSync("npm-groovy-fix-log-should-fix-only-some-errors.txt"), "Output txt file produced");
|
|
190
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
191
|
-
|
|
192
|
-
fse.removeSync("npm-groovy-fix-log-should-fix-only-some-errors.txt");
|
|
193
|
-
rimraf.sync(tmpDir);
|
|
194
|
-
checkCodeNarcCallsCounter(1);
|
|
195
|
-
}).timeout(120000);
|
|
196
|
-
|
|
197
|
-
it("(API:file) should fix groovy files", async function() {
|
|
198
|
-
const tmpDir = await copyFilesInTmpDir();
|
|
199
|
-
const linter = await new NpmGroovyLint(
|
|
200
|
-
[
|
|
201
|
-
process.execPath,
|
|
202
|
-
"",
|
|
203
|
-
"--path",
|
|
204
|
-
'"' + tmpDir + '"',
|
|
205
|
-
"--output",
|
|
206
|
-
'"npm-groovy-fix-log-should-fix-groovy-files.txt"',
|
|
207
|
-
"--fix",
|
|
208
|
-
"--nolintafter",
|
|
209
|
-
"--no-insight",
|
|
210
|
-
"--verbose"
|
|
211
|
-
],
|
|
212
|
-
{}
|
|
213
|
-
).run();
|
|
214
|
-
|
|
215
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
216
|
-
assert(linter.lintResult.summary.totalFixedNumber > 0, "Errors have been fixed");
|
|
217
|
-
assert(fse.existsSync("npm-groovy-fix-log-should-fix-groovy-files.txt"), "Output txt file produced");
|
|
218
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
219
|
-
|
|
220
|
-
fse.removeSync("npm-groovy-fix-log-should-fix-groovy-files.txt");
|
|
221
|
-
rimraf.sync(tmpDir);
|
|
222
|
-
checkCodeNarcCallsCounter(2);
|
|
223
|
-
}).timeout(120000);
|
|
224
|
-
});
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const NpmGroovyLint = require("../groovy-lint.js");
|
|
4
|
-
let assert = require("assert");
|
|
5
|
-
const fse = require("fs-extra");
|
|
6
|
-
const { normalizeNewLines } = require("../utils.js");
|
|
7
|
-
const rimraf = require("rimraf");
|
|
8
|
-
const {
|
|
9
|
-
beforeEachTestCase,
|
|
10
|
-
checkCodeNarcCallsCounter,
|
|
11
|
-
getDiff,
|
|
12
|
-
copyFilesInTmpDir,
|
|
13
|
-
SAMPLE_FILE_BIG,
|
|
14
|
-
SAMPLE_FILE_BIG_PATH,
|
|
15
|
-
SAMPLE_FILE_SMALL_PATH
|
|
16
|
-
} = require("./helpers/common");
|
|
17
|
-
|
|
18
|
-
describe("Format with API", function() {
|
|
19
|
-
beforeEach(beforeEachTestCase);
|
|
20
|
-
|
|
21
|
-
it("(API:source) should format code", async () => {
|
|
22
|
-
const expectedFixedErrs = 1096;
|
|
23
|
-
const prevFileContent = fse.readFileSync(SAMPLE_FILE_BIG_PATH).toString();
|
|
24
|
-
const npmGroovyLintConfig = {
|
|
25
|
-
source: prevFileContent,
|
|
26
|
-
format: true,
|
|
27
|
-
nolintafter: true,
|
|
28
|
-
output: "txt",
|
|
29
|
-
insight: false,
|
|
30
|
-
verbose: true
|
|
31
|
-
};
|
|
32
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
33
|
-
|
|
34
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
35
|
-
assert(
|
|
36
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
37
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
38
|
-
);
|
|
39
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
40
|
-
const fixedNbInLogs = (linter.outputString.match(/fixed/g) || []).length;
|
|
41
|
-
assert(fixedNbInLogs >= expectedFixedErrs, `Result log contains ${expectedFixedErrs} fixed errors (${fixedNbInLogs} returned)`);
|
|
42
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
43
|
-
checkCodeNarcCallsCounter(2);
|
|
44
|
-
}).timeout(100000);
|
|
45
|
-
|
|
46
|
-
it("(API:source) should format code with custom config", async () => {
|
|
47
|
-
const expectedFixedErrs = 34;
|
|
48
|
-
const prevFileContent = fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString();
|
|
49
|
-
const npmGroovyLintConfig = {
|
|
50
|
-
source: prevFileContent,
|
|
51
|
-
sourcefilepath: SAMPLE_FILE_SMALL_PATH,
|
|
52
|
-
config: "custom",
|
|
53
|
-
format: true,
|
|
54
|
-
nolintafter: true,
|
|
55
|
-
output: "txt",
|
|
56
|
-
insight: false,
|
|
57
|
-
verbose: true
|
|
58
|
-
};
|
|
59
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
60
|
-
|
|
61
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
62
|
-
assert(
|
|
63
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
64
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
65
|
-
);
|
|
66
|
-
assert(linter.lintResult.files[0].updatedSource && linter.lintResult.files[0].updatedSource !== prevFileContent, "Source has been updated");
|
|
67
|
-
const fixedNbInLogs = (linter.outputString.match(/fixed/g) || []).length;
|
|
68
|
-
assert(fixedNbInLogs >= expectedFixedErrs, `Result log contains ${expectedFixedErrs} fixed errors (${fixedNbInLogs} returned)`);
|
|
69
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
70
|
-
const rules = linter.options.rules || {};
|
|
71
|
-
assert(rules["Indentation"]["spacesPerIndentLevel"] === 2, "Indentation rule override has been taken in account");
|
|
72
|
-
checkCodeNarcCallsCounter(1);
|
|
73
|
-
}).timeout(100000);
|
|
74
|
-
|
|
75
|
-
it("(API:file) should format code", async () => {
|
|
76
|
-
const expectedFixedErrs = 1096;
|
|
77
|
-
const tmpDir = await copyFilesInTmpDir();
|
|
78
|
-
const prevFileContent = fse.readFileSync(SAMPLE_FILE_BIG_PATH).toString();
|
|
79
|
-
const npmGroovyLintConfig = {
|
|
80
|
-
path: tmpDir,
|
|
81
|
-
files: `**/${SAMPLE_FILE_BIG}`,
|
|
82
|
-
format: true,
|
|
83
|
-
nolintafter: true,
|
|
84
|
-
output: "txt",
|
|
85
|
-
insight: false,
|
|
86
|
-
verbose: true
|
|
87
|
-
};
|
|
88
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
89
|
-
|
|
90
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
91
|
-
assert(
|
|
92
|
-
linter.lintResult.summary.totalFixedNumber >= expectedFixedErrs,
|
|
93
|
-
`${expectedFixedErrs} errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
94
|
-
);
|
|
95
|
-
const newFileContent = fse.readFileSync(tmpDir + "/" + SAMPLE_FILE_BIG).toString();
|
|
96
|
-
assert(newFileContent !== prevFileContent, "File has been updated");
|
|
97
|
-
rimraf.sync(tmpDir);
|
|
98
|
-
const fixedNbInLogs = (linter.outputString.match(/fixed/g) || []).length;
|
|
99
|
-
assert(fixedNbInLogs >= expectedFixedErrs, `Result log contains ${expectedFixedErrs} fixed errors (${fixedNbInLogs} returned)`);
|
|
100
|
-
assert(!linter.outputString.includes("NaN"), "Results does not contain NaN");
|
|
101
|
-
checkCodeNarcCallsCounter(2);
|
|
102
|
-
|
|
103
|
-
rimraf.sync(tmpDir);
|
|
104
|
-
}).timeout(100000);
|
|
105
|
-
|
|
106
|
-
for (const [key, val] of getSamplesMap()) {
|
|
107
|
-
it("(API:source) " + key + " --format", async () => {
|
|
108
|
-
await checkRule(key, val, "format");
|
|
109
|
-
}).timeout(30000);
|
|
110
|
-
it("(API:source) " + key + " --fix", async () => {
|
|
111
|
-
await checkRule(key, val, "fix");
|
|
112
|
-
}).timeout(30000);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
async function checkRule(key, check, checkType) {
|
|
117
|
-
const source = normalizeNewLines(check.before);
|
|
118
|
-
const moreOptions = check.moreOptions ? check.moreOptions : {};
|
|
119
|
-
const npmGroovyLintConfig = Object.assign(
|
|
120
|
-
{
|
|
121
|
-
source: source,
|
|
122
|
-
nolintafter: true,
|
|
123
|
-
output: "none",
|
|
124
|
-
insight: false,
|
|
125
|
-
verbose: true
|
|
126
|
-
},
|
|
127
|
-
moreOptions
|
|
128
|
-
);
|
|
129
|
-
if (checkType == "format") {
|
|
130
|
-
npmGroovyLintConfig.format = true;
|
|
131
|
-
} else if (checkType == "fix") {
|
|
132
|
-
npmGroovyLintConfig.fix = true;
|
|
133
|
-
}
|
|
134
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
135
|
-
|
|
136
|
-
assert(
|
|
137
|
-
linter.lintResult.summary.totalFixedNumber >= check.totalFixed,
|
|
138
|
-
`${check.totalFixed} Errors have been fixed (${linter.lintResult.summary.totalFixedNumber} returned)`
|
|
139
|
-
);
|
|
140
|
-
const result = linter.lintResult.files[0].updatedSource;
|
|
141
|
-
const expectedResult = normalizeNewLines(check.after);
|
|
142
|
-
const effectiveDiff = getDiff(expectedResult, result, source);
|
|
143
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
144
|
-
assert(effectiveDiff.length === 0, "Code has been formatted correctly");
|
|
145
|
-
checkCodeNarcCallsCounter(check.codeNarcCallsCounter);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function getSamplesMap() {
|
|
149
|
-
return new Map([
|
|
150
|
-
[
|
|
151
|
-
"SourceWithIfElseBracesToFormat",
|
|
152
|
-
{
|
|
153
|
-
totalFixed: 4,
|
|
154
|
-
codeNarcCallsCounter: 2,
|
|
155
|
-
before: `
|
|
156
|
-
private void doSomething(){
|
|
157
|
-
if (a == 2)
|
|
158
|
-
doSomething();
|
|
159
|
-
}
|
|
160
|
-
`,
|
|
161
|
-
after: `
|
|
162
|
-
private void doSomething() {
|
|
163
|
-
if (a == 2) {
|
|
164
|
-
doSomething()
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
`
|
|
168
|
-
}
|
|
169
|
-
],
|
|
170
|
-
[
|
|
171
|
-
"OnlyNonCodeNarcFormatRules",
|
|
172
|
-
{
|
|
173
|
-
totalFixed: 0,
|
|
174
|
-
codeNarcCallsCounter: 1,
|
|
175
|
-
before: `
|
|
176
|
-
// There is a comment badly aligned here
|
|
177
|
-
if (a == 2) {
|
|
178
|
-
// And here too
|
|
179
|
-
x = 1
|
|
180
|
-
}
|
|
181
|
-
`,
|
|
182
|
-
after: `
|
|
183
|
-
// There is a comment badly aligned here
|
|
184
|
-
if (a == 2) {
|
|
185
|
-
// And here too
|
|
186
|
-
x = 1
|
|
187
|
-
}
|
|
188
|
-
`
|
|
189
|
-
}
|
|
190
|
-
],
|
|
191
|
-
[
|
|
192
|
-
"OverrideIndentation",
|
|
193
|
-
{
|
|
194
|
-
moreOptions: {
|
|
195
|
-
rulesets:
|
|
196
|
-
'Indentation{"spacesPerIndentLevel":2,"severity": "warning"},UnnecessarySemicolon,UnnecessaryGString,ConsecutiveBlankLines{"severity":"warning"},NoTabCharacter',
|
|
197
|
-
rulesetsoverridetype: "appendConfig"
|
|
198
|
-
},
|
|
199
|
-
totalFixed: 4,
|
|
200
|
-
codeNarcCallsCounter: 2,
|
|
201
|
-
before: `
|
|
202
|
-
private void doSomething(){
|
|
203
|
-
if (a == 2)
|
|
204
|
-
doSomething();
|
|
205
|
-
}
|
|
206
|
-
`,
|
|
207
|
-
after: `
|
|
208
|
-
private void doSomething() {
|
|
209
|
-
if (a == 2) {
|
|
210
|
-
doSomething()
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
`
|
|
214
|
-
}
|
|
215
|
-
],
|
|
216
|
-
[
|
|
217
|
-
"ElseIfMustRemainSeparated",
|
|
218
|
-
{
|
|
219
|
-
totalFixed: 1,
|
|
220
|
-
codeNarcCallsCounter: 1,
|
|
221
|
-
before: `
|
|
222
|
-
boolean foo(boolean a, boolean b) {
|
|
223
|
-
if (a) {
|
|
224
|
-
return true
|
|
225
|
-
} else if(b) {
|
|
226
|
-
return true
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
`,
|
|
230
|
-
after: `
|
|
231
|
-
boolean foo(boolean a, boolean b) {
|
|
232
|
-
if (a) {
|
|
233
|
-
return true
|
|
234
|
-
} else if (b) {
|
|
235
|
-
return true
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
`
|
|
239
|
-
}
|
|
240
|
-
],
|
|
241
|
-
// https://github.com/nvuillam/npm-groovy-lint/issues/121
|
|
242
|
-
[
|
|
243
|
-
"Issue121",
|
|
244
|
-
{
|
|
245
|
-
totalFixed: 1,
|
|
246
|
-
codeNarcCallsCounter: 1,
|
|
247
|
-
before: `
|
|
248
|
-
pipeline {
|
|
249
|
-
agent any
|
|
250
|
-
stages {
|
|
251
|
-
stage('Intall JQ') {
|
|
252
|
-
steps {
|
|
253
|
-
script {
|
|
254
|
-
sh 'apt update; apt install jq=1.5+dfsg-2+b1 -y'
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
`,
|
|
261
|
-
after: `
|
|
262
|
-
pipeline {
|
|
263
|
-
agent any
|
|
264
|
-
stages {
|
|
265
|
-
stage('Intall JQ') {
|
|
266
|
-
steps {
|
|
267
|
-
script {
|
|
268
|
-
sh 'apt update; apt install jq=1.5+dfsg-2+b1 -y'
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
`
|
|
275
|
-
/* TODO: update CodeNarc or Groovy so that the good "after" can be uncommented !
|
|
276
|
-
after: `
|
|
277
|
-
pipeline {
|
|
278
|
-
agent any
|
|
279
|
-
stages {
|
|
280
|
-
stage('Intall JQ') {
|
|
281
|
-
steps {
|
|
282
|
-
script {
|
|
283
|
-
sh 'apt update; apt install jq=1.5+dfsg-2+b1 -y'
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
` */
|
|
290
|
-
}
|
|
291
|
-
]
|
|
292
|
-
]);
|
|
293
|
-
}
|