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,43 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
let assert = require("assert");
|
|
4
|
-
const util = require("util");
|
|
5
|
-
const fse = require("fs-extra");
|
|
6
|
-
const rimraf = require("rimraf");
|
|
7
|
-
const childProcess = require("child_process");
|
|
8
|
-
const exec = util.promisify(childProcess.exec);
|
|
9
|
-
const { beforeEachTestCase, copyFilesInTmpDir, SAMPLE_FILE_SMALL, SAMPLE_FILE_SMALL_FORMAT, NPM_GROOVY_LINT } = require("./helpers/common");
|
|
10
|
-
|
|
11
|
-
describe("Lint & format with EXE", function() {
|
|
12
|
-
beforeEach(beforeEachTestCase);
|
|
13
|
-
|
|
14
|
-
it("(API:file) should lint and format a file in one shot", async function() {
|
|
15
|
-
const tmpDir = await copyFilesInTmpDir();
|
|
16
|
-
const prevFileContent = fse.readFileSync(tmpDir + "/" + SAMPLE_FILE_SMALL).toString();
|
|
17
|
-
const params = [
|
|
18
|
-
"--output",
|
|
19
|
-
'"npm-groovy-fix-log.json"',
|
|
20
|
-
"--path",
|
|
21
|
-
'"' + tmpDir + '"',
|
|
22
|
-
"--files",
|
|
23
|
-
"**/" + SAMPLE_FILE_SMALL,
|
|
24
|
-
"--format",
|
|
25
|
-
"--no-insight",
|
|
26
|
-
"--verbose"
|
|
27
|
-
];
|
|
28
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
29
|
-
if (stderr) {
|
|
30
|
-
console.error(stderr);
|
|
31
|
-
}
|
|
32
|
-
assert(stdout, "stdout is set");
|
|
33
|
-
|
|
34
|
-
assert(fse.existsSync("npm-groovy-fix-log.json"), "Output json file has been produced");
|
|
35
|
-
|
|
36
|
-
const newFileContent = fse.readFileSync(tmpDir + "/" + SAMPLE_FILE_SMALL).toString();
|
|
37
|
-
assert(prevFileContent !== newFileContent, "Groovy file has been updated");
|
|
38
|
-
const expectedFileContent = fse.readFileSync(tmpDir + "/" + SAMPLE_FILE_SMALL_FORMAT).toString();
|
|
39
|
-
assert.strictEqual(newFileContent, expectedFileContent, "Formatted file is corresponding to expected result");
|
|
40
|
-
fse.removeSync("npm-groovy-fix-log.json");
|
|
41
|
-
rimraf.sync(tmpDir);
|
|
42
|
-
}).timeout(120000);
|
|
43
|
-
});
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const util = require("util");
|
|
4
|
-
const c = require("ansi-colors");
|
|
5
|
-
let assert = require("assert");
|
|
6
|
-
const fse = require("fs-extra");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const childProcess = require("child_process");
|
|
9
|
-
const exec = util.promisify(childProcess.exec);
|
|
10
|
-
const spawn = childProcess.spawnSync;
|
|
11
|
-
|
|
12
|
-
const { SAMPLE_FILE_SMALL, NPM_GROOVY_LINT } = require("./helpers/common");
|
|
13
|
-
|
|
14
|
-
describe("Lint with executable", () => {
|
|
15
|
-
it("(EXE:file) should generate text console output", async () => {
|
|
16
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--loglevel", "warning", "--no-insight", "--verbose"];
|
|
17
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
18
|
-
if (stderr) {
|
|
19
|
-
console.error(stderr);
|
|
20
|
-
}
|
|
21
|
-
assert(stdout, "stdout is set");
|
|
22
|
-
assert(stdout.includes("warning"), 'stdout should contain word "warning"');
|
|
23
|
-
});
|
|
24
|
-
it("(EXE:file) should generate json console output", async () => {
|
|
25
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--no-insight", "--output", "json"];
|
|
26
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
27
|
-
if (stderr) {
|
|
28
|
-
console.error(stderr);
|
|
29
|
-
}
|
|
30
|
-
assert(stdout, "stdout is set");
|
|
31
|
-
assert(stdout.includes(`"totalFoundWarningNumber":`), "Property totalFoundWarningNumber is in result");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("(EXE:file) should ignore fake_node_modules pattern", async () => {
|
|
35
|
-
const params = ["--ignorepattern", "**/fake_node_modules/**", "--no-insight", "--output", "txt"];
|
|
36
|
-
const { stdout, stderr } = await exec("cd lib/example && " + NPM_GROOVY_LINT + params.join(" "));
|
|
37
|
-
if (stderr) {
|
|
38
|
-
console.error(stderr);
|
|
39
|
-
}
|
|
40
|
-
assert(stdout, "stdout is set");
|
|
41
|
-
assert(!stdout.includes(`ToIgnore.groovy`), `ToIgnore.groovy has been ignored \n${stdout}`);
|
|
42
|
-
assert(
|
|
43
|
-
stdout.includes(`npm-groovy-lint results in ${c.bold(10)} linted files`),
|
|
44
|
-
`Number of linted files is displayed in summary \n${stdout}`
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("(EXE:file) should generate codenarc HTML file report", async () => {
|
|
49
|
-
const reportFileName = path.resolve("ReportTestCodenarc.html");
|
|
50
|
-
const params = [
|
|
51
|
-
"--codenarcargs",
|
|
52
|
-
'-basedir="lib/example"',
|
|
53
|
-
'-title="TestTitleCodenarc"',
|
|
54
|
-
"-maxPriority1Violations=0",
|
|
55
|
-
`-report="html:${reportFileName}"`
|
|
56
|
-
];
|
|
57
|
-
await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
58
|
-
assert(fse.existsSync(reportFileName), "html CodeNarc report has been generated at " + reportFileName);
|
|
59
|
-
fse.removeSync(reportFileName);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("(EXE:file) should generate codenarc XML file report", async () => {
|
|
63
|
-
const reportFileName = path.resolve("ReportTestCodenarc.xml");
|
|
64
|
-
const params = [
|
|
65
|
-
"--codenarcargs",
|
|
66
|
-
'-basedir="lib/example"',
|
|
67
|
-
'-title="TestTitleCodenarc"',
|
|
68
|
-
"-maxPriority1Violations=0",
|
|
69
|
-
`-report="xml:${reportFileName}"`
|
|
70
|
-
];
|
|
71
|
-
await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
72
|
-
assert(fse.existsSync(reportFileName), "xml CodeNarc report has been generated at " + reportFileName);
|
|
73
|
-
fse.removeSync(reportFileName);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("(EXE:file) should run on a Jenkinsfile", async () => {
|
|
77
|
-
const params = ["--path", ' "lib/example"', "--files", "**/Jenkinsfile", "-c", "recommended-jenkinsfile", "--no-insight", "--verbose"];
|
|
78
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
79
|
-
if (stderr) {
|
|
80
|
-
console.error(stderr);
|
|
81
|
-
}
|
|
82
|
-
assert(stdout, "stdout is set");
|
|
83
|
-
assert(stdout.includes("warning"), 'stdout should contain word "warning"');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("(EXE:help) should show npm-groovy-lint help", async () => {
|
|
87
|
-
const params = ["-h"];
|
|
88
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
89
|
-
if (stderr) {
|
|
90
|
-
console.error(stderr);
|
|
91
|
-
}
|
|
92
|
-
assert(stdout, "stdout is set");
|
|
93
|
-
assert(stdout.includes("--verbose"), 'stdout should contain word "--verbose"');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("(EXE:help) should show npm-groovy-lint version", async () => {
|
|
97
|
-
const params = ["-v"];
|
|
98
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
99
|
-
if (stderr) {
|
|
100
|
-
console.error(stderr);
|
|
101
|
-
}
|
|
102
|
-
assert(stdout, "stdout is set");
|
|
103
|
-
assert(stdout.includes("npm-groovy-lint v"), "Version is returned");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("(EXE:help) should show codenarc help", async () => {
|
|
107
|
-
const params = ["--codenarcargs", "-help"];
|
|
108
|
-
const { stdout, stderr } = await exec(NPM_GROOVY_LINT + params.join(" "));
|
|
109
|
-
if (stderr) {
|
|
110
|
-
console.error(stderr);
|
|
111
|
-
}
|
|
112
|
-
assert(stdout, "stdout is set");
|
|
113
|
-
assert(
|
|
114
|
-
stdout.includes("where OPTIONS are zero or more command-line options"),
|
|
115
|
-
'stdout should contain word "where OPTIONS are zero or more command-line options"'
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("(EXE:file) failonerror", async () => {
|
|
120
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--failonerror", "--no-insight", "--output", "txt"];
|
|
121
|
-
const { stderr, status } = spawn(NPM_GROOVY_LINT + params.join(" "), [], { shell: true });
|
|
122
|
-
if (stderr) {
|
|
123
|
-
console.error(stderr.toString());
|
|
124
|
-
}
|
|
125
|
-
assert(status === 1, `Status code is 1 (returned: ${status})`);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("(EXE:file) failonwarning", async () => {
|
|
129
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--failonwarning", "--no-insight", "--output", "txt"];
|
|
130
|
-
const { stderr, status } = spawn(NPM_GROOVY_LINT + params.join(" "), [], { shell: true });
|
|
131
|
-
if (stderr) {
|
|
132
|
-
console.error(stderr.toString());
|
|
133
|
-
}
|
|
134
|
-
assert(status === 1, `Status code is 1 (returned: ${status})`);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("(EXE:file) failoninfo", async () => {
|
|
138
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--failoninfo", "--no-insight", "--output", "txt"];
|
|
139
|
-
const { stderr, status } = spawn(NPM_GROOVY_LINT + params.join(" "), [], { shell: true });
|
|
140
|
-
if (stderr) {
|
|
141
|
-
console.error(stderr.toString());
|
|
142
|
-
}
|
|
143
|
-
assert(status === 1, `Status code is 1 (returned: ${status})`);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("(EXE:file) failon info", async () => {
|
|
147
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--failon", "info", "--no-insight", "--output", "txt"];
|
|
148
|
-
const { stderr, status } = spawn(NPM_GROOVY_LINT + params.join(" "), [], { shell: true });
|
|
149
|
-
if (stderr) {
|
|
150
|
-
console.error(stderr.toString());
|
|
151
|
-
}
|
|
152
|
-
assert(status === 1, `Status code is 1 (returned: ${status})`);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("(EXE:file) Send anonymous usage stats", async () => {
|
|
156
|
-
const params = ["--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--output", "txt"];
|
|
157
|
-
const { stdout, stderr, status } = spawn(NPM_GROOVY_LINT + params.join(" "), [], { shell: true });
|
|
158
|
-
if (stdout) {
|
|
159
|
-
console.log("STDOUT:\n");
|
|
160
|
-
console.log(stdout.toString());
|
|
161
|
-
}
|
|
162
|
-
if (stderr) {
|
|
163
|
-
console.log("STDERR:\n");
|
|
164
|
-
console.error(stderr.toString());
|
|
165
|
-
}
|
|
166
|
-
assert(status === 0, `Status code is 0 (returned: ${status})`);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
#! /usr/bin / env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const NpmGroovyLint = require("../groovy-lint.js");
|
|
4
|
-
let assert = require("assert");
|
|
5
|
-
const { beforeEachTestCase, checkCodeNarcCallsCounter } = require("./helpers/common");
|
|
6
|
-
|
|
7
|
-
describe("Check disabled rules", function() {
|
|
8
|
-
beforeEach(beforeEachTestCase);
|
|
9
|
-
|
|
10
|
-
for (const [key, val] of getSamplesMap()) {
|
|
11
|
-
it("(API:source)" + key, async () => {
|
|
12
|
-
await checkRule(key, val);
|
|
13
|
-
}).timeout(30000);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
async function checkRule(key, check) {
|
|
18
|
-
const npmGroovyLintConfig = {
|
|
19
|
-
source: check.source,
|
|
20
|
-
output: "txt",
|
|
21
|
-
insight: false,
|
|
22
|
-
verbose: true
|
|
23
|
-
};
|
|
24
|
-
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
25
|
-
|
|
26
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
27
|
-
assert(
|
|
28
|
-
linter.lintResult.summary.totalFoundNumber === check.totalFound,
|
|
29
|
-
`${linter.lintResult.summary.totalFoundNumber} errors found (expected: ${check.totalFound})`
|
|
30
|
-
);
|
|
31
|
-
checkCodeNarcCallsCounter(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getSamplesMap() {
|
|
35
|
-
return new Map([
|
|
36
|
-
[
|
|
37
|
-
"GroovyDisableFileAll/*",
|
|
38
|
-
{
|
|
39
|
-
totalFound: 0,
|
|
40
|
-
source: `
|
|
41
|
-
/* groovylint-disable */
|
|
42
|
-
private void doSomething(){
|
|
43
|
-
if (a == 2)
|
|
44
|
-
doSomething();
|
|
45
|
-
}
|
|
46
|
-
`
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
[
|
|
50
|
-
"GroovyDisableFileAll//",
|
|
51
|
-
{
|
|
52
|
-
totalFound: 0,
|
|
53
|
-
source: `
|
|
54
|
-
// groovylint-disable
|
|
55
|
-
private void doSomething(){
|
|
56
|
-
if (a == 2)
|
|
57
|
-
doSomething();
|
|
58
|
-
}
|
|
59
|
-
`
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
[
|
|
63
|
-
"GroovyDisableFileIndentation/*",
|
|
64
|
-
{
|
|
65
|
-
totalFound: 3,
|
|
66
|
-
source: `
|
|
67
|
-
/* groovylint-disable Indentation */
|
|
68
|
-
private void doSomething(){
|
|
69
|
-
if (a == 2)
|
|
70
|
-
doSomething();
|
|
71
|
-
}
|
|
72
|
-
`
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
[
|
|
76
|
-
"GroovyDisableFileIndentation//",
|
|
77
|
-
{
|
|
78
|
-
totalFound: 3,
|
|
79
|
-
source: `
|
|
80
|
-
// groovylint-disable Indentation
|
|
81
|
-
private void doSomething(){
|
|
82
|
-
if (a == 2)
|
|
83
|
-
doSomething();
|
|
84
|
-
}
|
|
85
|
-
`
|
|
86
|
-
}
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
"GroovyDisableFileIndentationUnnecessarySemicolon",
|
|
90
|
-
{
|
|
91
|
-
totalFound: 2,
|
|
92
|
-
source: `
|
|
93
|
-
// groovylint-disable Indentation,UnnecessarySemicolon
|
|
94
|
-
private void doSomething(){
|
|
95
|
-
if (a == 2)
|
|
96
|
-
doSomething();
|
|
97
|
-
}
|
|
98
|
-
`
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
"GroovyDisableLineAll",
|
|
103
|
-
{
|
|
104
|
-
totalFound: 4,
|
|
105
|
-
source: `
|
|
106
|
-
private void doSomething(){
|
|
107
|
-
if (a == 2)
|
|
108
|
-
doSomething(); // groovylint-disable-line
|
|
109
|
-
}
|
|
110
|
-
`
|
|
111
|
-
}
|
|
112
|
-
],
|
|
113
|
-
[
|
|
114
|
-
"GroovyDisableLineUnnecessarySemicolon",
|
|
115
|
-
{
|
|
116
|
-
totalFound: 3,
|
|
117
|
-
source: `
|
|
118
|
-
private void doSomething(){
|
|
119
|
-
if (a == 2)
|
|
120
|
-
doSomething(); // groovylint-disable-line UnnecessarySemicolon
|
|
121
|
-
}
|
|
122
|
-
`
|
|
123
|
-
}
|
|
124
|
-
],
|
|
125
|
-
[
|
|
126
|
-
"GroovyDisableNextLineUnnecessarySemicolon",
|
|
127
|
-
{
|
|
128
|
-
totalFound: 3,
|
|
129
|
-
source: `
|
|
130
|
-
private void doSomething(){
|
|
131
|
-
if (a == 2)
|
|
132
|
-
// groovylint-disable-next-line UnnecessarySemicolon
|
|
133
|
-
doSomething();
|
|
134
|
-
}
|
|
135
|
-
`
|
|
136
|
-
}
|
|
137
|
-
],
|
|
138
|
-
[
|
|
139
|
-
"GroovyDisableNextLineToIgnore",
|
|
140
|
-
{
|
|
141
|
-
totalFound: 4,
|
|
142
|
-
source: `
|
|
143
|
-
private void doSomething(){
|
|
144
|
-
if (a == 2)
|
|
145
|
-
// groovylint-disable-next-line DummyRule
|
|
146
|
-
doSomething();
|
|
147
|
-
}
|
|
148
|
-
`
|
|
149
|
-
}
|
|
150
|
-
],
|
|
151
|
-
[
|
|
152
|
-
"GroovyDisableEnableAll",
|
|
153
|
-
{
|
|
154
|
-
totalFound: 3,
|
|
155
|
-
source: `
|
|
156
|
-
private void doSomething(){
|
|
157
|
-
// groovylint-disable
|
|
158
|
-
if (a == 2)
|
|
159
|
-
doSomething();
|
|
160
|
-
// groovylint-enable
|
|
161
|
-
def a = 1;
|
|
162
|
-
}
|
|
163
|
-
`
|
|
164
|
-
}
|
|
165
|
-
],
|
|
166
|
-
[
|
|
167
|
-
"GroovyDisableEnableIndentation",
|
|
168
|
-
{
|
|
169
|
-
totalFound: 6,
|
|
170
|
-
source: `
|
|
171
|
-
private void doSomething(){
|
|
172
|
-
/* groovylint-disable Indentation */
|
|
173
|
-
if (a == 2)
|
|
174
|
-
doSomething();
|
|
175
|
-
/* groovylint-enable Indentation */
|
|
176
|
-
def a = 1;
|
|
177
|
-
}
|
|
178
|
-
`
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
|
-
[
|
|
182
|
-
"GroovyDisableEnableIndentationUnnecessarySemicolon",
|
|
183
|
-
{
|
|
184
|
-
totalFound: 5,
|
|
185
|
-
source: `
|
|
186
|
-
private void doSomething(){
|
|
187
|
-
/* groovylint-disable Indentation, UnnecessarySemicolon */
|
|
188
|
-
if (a == 2)
|
|
189
|
-
doSomething();
|
|
190
|
-
/* groovylint-enable Indentation, UnnecessarySemicolon */
|
|
191
|
-
def a = 1;
|
|
192
|
-
}
|
|
193
|
-
`
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
]);
|
|
197
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const NpmGroovyLint = require("../groovy-lint.js");
|
|
4
|
-
const { getNpmGroovyLintRules } = require("../groovy-lint-rules.js");
|
|
5
|
-
const { normalizeNewLines } = require("../utils.js");
|
|
6
|
-
let assert = require("assert");
|
|
7
|
-
|
|
8
|
-
const { beforeEachTestCase, checkCodeNarcCallsCounter, getDiff } = require("./helpers/common");
|
|
9
|
-
const npmGroovyLintRules = getNpmGroovyLintRules({ loadTests: true });
|
|
10
|
-
|
|
11
|
-
// Read rules file and test all fixes
|
|
12
|
-
describe("Check rules auto-fixes", () => {
|
|
13
|
-
beforeEach(beforeEachTestCase);
|
|
14
|
-
|
|
15
|
-
// Iterate all rules
|
|
16
|
-
for (const ruleName of Object.keys(npmGroovyLintRules)) {
|
|
17
|
-
let pos = 1;
|
|
18
|
-
// Process only the rules with a fix defined
|
|
19
|
-
if (npmGroovyLintRules[ruleName].fix && npmGroovyLintRules[ruleName]) {
|
|
20
|
-
if (npmGroovyLintRules[ruleName].tests && npmGroovyLintRules[ruleName].tests.length > 0) {
|
|
21
|
-
// Process rule tests
|
|
22
|
-
for (const testRule of npmGroovyLintRules[ruleName].tests) {
|
|
23
|
-
// Do not test non-codenarc rules, as they can't be returned by CodeNarc Linter
|
|
24
|
-
if (npmGroovyLintRules[ruleName].isCodeNarcRule == null || npmGroovyLintRules[ruleName].isCodeNarcRule === true)
|
|
25
|
-
it(`${ruleName} (${pos})`, async () => {
|
|
26
|
-
await checkRuleFix(ruleName, testRule);
|
|
27
|
-
}).timeout(60000);
|
|
28
|
-
pos = pos + 1;
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
// At least one rule should be defined
|
|
32
|
-
it(`${ruleName} fix tests has not been defined: please do it !`, async () => {
|
|
33
|
-
assert(0 === 1, `${ruleName} fix tests has not been defined: please do it !`);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Check rule fix result
|
|
41
|
-
async function checkRuleFix(ruleName, testRule) {
|
|
42
|
-
let fixRules = ruleName;
|
|
43
|
-
// Call linter & fixer
|
|
44
|
-
const source = normalizeNewLines(testRule.sourceBefore);
|
|
45
|
-
const npmGroovyLintConfig = {
|
|
46
|
-
source: source,
|
|
47
|
-
rulesets: fixRules,
|
|
48
|
-
fix: true,
|
|
49
|
-
fixrules: fixRules,
|
|
50
|
-
nolintafter: true,
|
|
51
|
-
insight: false,
|
|
52
|
-
output: "none",
|
|
53
|
-
verbose: true
|
|
54
|
-
};
|
|
55
|
-
let err = null;
|
|
56
|
-
let linter;
|
|
57
|
-
try {
|
|
58
|
-
linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
|
|
59
|
-
} catch (e) {
|
|
60
|
-
console.error("NpmGroovyLint fatal error: " + e.message);
|
|
61
|
-
console.error(e.stack);
|
|
62
|
-
err = e;
|
|
63
|
-
}
|
|
64
|
-
// Check results
|
|
65
|
-
assert(err == null, "No crash during NpmGroovyLint run");
|
|
66
|
-
assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
|
|
67
|
-
const updatedSource = linter.lintResult.files[0].updatedSource;
|
|
68
|
-
const effectiveDiffs = getDiff(normalizeNewLines(testRule.sourceAfter), updatedSource, source);
|
|
69
|
-
assert(effectiveDiffs.length === 0, `Fix result is not the one expected.\n Diff: \n${JSON.stringify(effectiveDiffs, null, 2)}`);
|
|
70
|
-
checkCodeNarcCallsCounter(testRule.codeNarcCallsNumber || 1);
|
|
71
|
-
}
|