npm-groovy-lint 8.1.1 → 9.2.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/README.md +8 -5
  3. package/lib/.groovylintrc-all.json +6 -0
  4. package/lib/codenarc-caller.js +16 -8
  5. package/lib/config.js +2 -2
  6. package/lib/example/RuleSet-All.groovy +417 -409
  7. package/lib/example/SampleFile.groovy +0 -8
  8. package/lib/example/SampleFileSmall.groovy +0 -6
  9. package/lib/example/SampleFileSmallFixed.txt +0 -5
  10. package/lib/example/SampleFileSmallFormatted.txt +0 -6
  11. package/lib/groovy-lint-fix.js +0 -2
  12. package/lib/groovy-lint.js +0 -2
  13. package/lib/java/CodeNarc-2.2.0.jar +0 -0
  14. package/lib/java/CodeNarcServer.jar +0 -0
  15. package/lib/java/groovy/lib/{ant-1.10.8.jar → ant-1.10.11.jar} +0 -0
  16. package/lib/java/groovy/lib/ant-launcher-1.10.11.jar +0 -0
  17. package/lib/java/groovy/lib/{groovy-3.0.5.jar → groovy-3.0.9.jar} +0 -0
  18. package/lib/java/groovy/lib/{groovy-ant-3.0.5.jar → groovy-ant-3.0.9.jar} +0 -0
  19. package/lib/java/groovy/lib/{groovy-json-3.0.5.jar → groovy-json-3.0.9.jar} +0 -0
  20. package/lib/java/groovy/lib/{groovy-templates-3.0.5.jar → groovy-templates-3.0.9.jar} +0 -0
  21. package/lib/java/groovy/lib/{groovy-xml-3.0.5.jar → groovy-xml-3.0.9.jar} +0 -0
  22. package/lib/java/log4j-api-2.17.0.jar +0 -0
  23. package/lib/java/log4j-core-2.17.0.jar +0 -0
  24. package/lib/java/log4j-slf4j-impl-2.17.0.jar +0 -0
  25. package/package.json +16 -14
  26. package/lib/java/CodeNarc-2.0.0.jar +0 -0
  27. package/lib/java/groovy/lib/ant-launcher-1.10.8.jar +0 -0
  28. package/lib/java/log4j-api-2.13.0.jar +0 -0
  29. package/lib/java/log4j-core-2.13.0.jar +0 -0
  30. package/lib/java/log4j-slf4j-impl-2.13.0.jar +0 -0
  31. package/lib/test/errors.test.js +0 -92
  32. package/lib/test/helpers/common.js +0 -84
  33. package/lib/test/helpers/init.js +0 -29
  34. package/lib/test/lint-api.test.js +0 -221
  35. package/lib/test/lint-build-fix.test.js +0 -43
  36. package/lib/test/lint-build-format.test.js +0 -43
  37. package/lib/test/lint-build.test.js +0 -168
  38. package/lib/test/lint-comments.test.js +0 -197
  39. package/lib/test/lint-fix.rules.test.js +0 -71
  40. package/lib/test/lint-fix.test.js +0 -224
  41. package/lib/test/lint-format.test.js +0 -293
  42. package/lib/test/miscellaneous.test.js +0 -326
@@ -1,326 +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 os = require("os");
7
- const path = require("path");
8
- const which = require("which");
9
- const { beforeEachTestCase, checkCodeNarcCallsCounter, SAMPLE_FILE_BIG, SAMPLE_FILE_SMALL, SAMPLE_FILE_SMALL_PATH } = require("./helpers/common");
10
-
11
- describe("Miscellaneous", function() {
12
- beforeEach(beforeEachTestCase);
13
-
14
- it("(API:source) returns config file using path", async () => {
15
- const npmGroovyLintConfig = {
16
- path: "./lib/example/",
17
- files: "**/" + SAMPLE_FILE_SMALL,
18
- output: "txt",
19
- insight: false,
20
- verbose: true
21
- };
22
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
23
- const filePath = await linter.getConfigFilePath();
24
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
25
- assert(path.resolve(filePath) === path.resolve("./lib/example/.groovylintrc.json"), ".groovylintrc.json has been returned");
26
- });
27
-
28
- it("(API:source) returns config file path using parameter", async () => {
29
- const npmGroovyLintConfig = {};
30
- const linter = new NpmGroovyLint(npmGroovyLintConfig, {});
31
- const filePath = await linter.getConfigFilePath("./lib/example");
32
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
33
- assert(path.resolve(filePath) === path.resolve("./lib/example/.groovylintrc.json"), ".groovylintrc.json has been returned");
34
- });
35
-
36
- it("(API:source) load config using specific file name", async () => {
37
- const customConfigFilePath = process.platform.includes("linux") ? "~/.groovylintrc-custom.json" : os.tmpdir() + "\\.groovylintrc-custom.json";
38
- await fse.ensureDir("~/", { mode: "0777" });
39
- await fse.copy("./lib/example/.groovylintrc-custom.json", customConfigFilePath);
40
- const npmGroovyLintConfig = {
41
- config: customConfigFilePath,
42
- path: "./lib/example/",
43
- files: "**/" + SAMPLE_FILE_SMALL,
44
- output: "txt",
45
- insight: false,
46
- verbose: true
47
- };
48
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
49
- await fse.remove(customConfigFilePath);
50
- const rules = linter.options.rules || {};
51
- assert(rules["CompileStatic"] == "off", "CompileStatic is off");
52
- assert(rules["CouldBeElvis"] == "off", "CouldBeElvis is off");
53
- assert(rules["NoDef"] == "off", "NoDef is off");
54
- assert(rules["Indentation"]["spacesPerIndentLevel"] === 2, "Indentation rule override has been taken in account");
55
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
56
- });
57
-
58
- it("(API:source) load standard config using string key", async () => {
59
- const npmGroovyLintConfig = {
60
- config: "recommended-jenkinsfile",
61
- path: "./lib/example/",
62
- files: "**/" + SAMPLE_FILE_SMALL,
63
- insight: false,
64
- output: "txt",
65
- verbose: true
66
- };
67
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
68
- const rules = linter.options.rules || {};
69
- assert(
70
- rules["UnusedVariable"] && rules["UnusedVariable"]["ignoreVariableNames"] == "_",
71
- `UnusedVariable.ignoreVariableNames = '_' not found `
72
- );
73
- assert(rules["NoDef"] == "off", "NoDef is off");
74
- assert(rules["VariableName"] == "off", "VariableName is off");
75
- assert(rules["CompileStatic"] == "off", "CompileStatic is off");
76
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
77
- });
78
-
79
- it("(API:source) load custom config using string key", async () => {
80
- const npmGroovyLintConfig = {
81
- config: "custom-jenkinsfile",
82
- path: "./lib/example/",
83
- files: "**/" + SAMPLE_FILE_SMALL,
84
- output: "txt",
85
- insight: false,
86
- verbose: true
87
- };
88
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
89
- const rules = linter.options.rules || {};
90
- assert(
91
- rules["UnusedVariable"] && rules["UnusedVariable"]["ignoreVariableNames"] == "_",
92
- `UnusedVariable.ignoreVariableNames = '_' not found `
93
- );
94
- assert(rules["NoDef"] == "off", "NoDef is off");
95
- assert(rules["VariableName"] && rules["VariableName"]["severity"] === "info", "VariableName is severity info");
96
- assert(rules["CompileStatic"] == "off", "CompileStatic is off");
97
- assert(rules["CouldBeSwitchStatement"] == "off", "CouldBeSwitchStatement is off");
98
- assert(rules["CouldBeElvis"] == "off", "CouldBeElvis is off");
99
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
100
- });
101
-
102
- it("(API:source) return indent length without linting", async () => {
103
- let indentLength = null;
104
- const linter = new NpmGroovyLint(
105
- {
106
- sourcefilepath: SAMPLE_FILE_SMALL_PATH,
107
- insight: false,
108
- output: "none"
109
- },
110
- {}
111
- );
112
- const tmpStartPath = path.dirname(SAMPLE_FILE_SMALL_PATH);
113
- let tmpConfigFilePath = await linter.getConfigFilePath(tmpStartPath);
114
- if (tmpConfigFilePath) {
115
- const configUser = await linter.loadConfig(tmpConfigFilePath, "format");
116
- if (configUser.rules && configUser.rules["Indentation"] && configUser.rules["Indentation"]["spacesPerIndentLevel"]) {
117
- indentLength = configUser.rules["Indentation"]["spacesPerIndentLevel"];
118
- }
119
- }
120
- assert(indentLength != null && indentLength > 0, "Indent length has been returned");
121
- });
122
-
123
- it("(API:source) return rules", async () => {
124
- const npmGroovyLintConfig = {
125
- path: "./lib/example/",
126
- files: "**/" + SAMPLE_FILE_SMALL,
127
- returnrules: true,
128
- insight: false,
129
- output: "none"
130
- };
131
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
132
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
133
- assert(linter.lintResult.rules != null, "Rules are returned ");
134
- assert(linter.lintResult.rules["AssertWithinFinallyBlock"].docUrl != null, "Rules doc urls are returned ");
135
- });
136
-
137
- it("(API:source) do not return rules", async () => {
138
- const npmGroovyLintConfig = {
139
- path: "./lib/example/",
140
- files: "**/" + SAMPLE_FILE_SMALL,
141
- insight: false,
142
- output: "none"
143
- };
144
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
145
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
146
- assert(linter.lintResult.rules == null, "Rules are not returned");
147
- });
148
-
149
- it("(API:source) send anonymous usage statistics", async () => {
150
- const npmGroovyLintConfig = {
151
- path: "./lib/example/",
152
- returnrules: true,
153
- output: "txt"
154
- };
155
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
156
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
157
- assert(linter.startElapse != null, "Anonymous stats has not been sent");
158
- });
159
-
160
- it("(API:source) should use a CodeNarc ruleset defined in groovylintrc.json", async () => {
161
- const npmGroovyLintConfig = {
162
- config: "./lib/example/.groovylintrc-codenarc-rulesets.json",
163
- path: "./lib/example/",
164
- files: "**/" + SAMPLE_FILE_SMALL,
165
- output: "txt"
166
- };
167
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
168
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
169
- });
170
-
171
- it("(API:source) should cancel current request", async () => {
172
- const requestKey = "requestKeyCalculatedByExternal" + Math.random();
173
- const delay = os.platform() === "win32" ? 500 : 300;
174
- const npmGroovyLintConfig = {
175
- path: "./lib/example/",
176
- files: "**/" + SAMPLE_FILE_BIG,
177
- insight: false,
178
- output: "none"
179
- };
180
- const linterProms = [];
181
- const linter1 = new NpmGroovyLint(npmGroovyLintConfig, {
182
- requestKey: requestKey
183
- });
184
- linterProms.push(linter1.run());
185
- await sleepPromise(delay);
186
- const linter2 = new NpmGroovyLint(npmGroovyLintConfig, {
187
- requestKey: requestKey
188
- });
189
- linterProms.push(linter2.run());
190
- await sleepPromise(delay);
191
- const linter3 = new NpmGroovyLint(npmGroovyLintConfig, {
192
- requestKey: requestKey
193
- });
194
- linterProms.push(linter3.run());
195
- await sleepPromise(delay);
196
- const linter4 = new NpmGroovyLint(npmGroovyLintConfig, {
197
- requestKey: requestKey
198
- });
199
- linterProms.push(linter4.run());
200
- await sleepPromise(delay);
201
- const linter5 = new NpmGroovyLint(npmGroovyLintConfig, {
202
- requestKey: requestKey
203
- });
204
- linterProms.push(linter5.run());
205
- await sleepPromise(delay);
206
- const linter6 = new NpmGroovyLint(npmGroovyLintConfig, {
207
- requestKey: requestKey
208
- });
209
- linterProms.push(linter6.run());
210
- await sleepPromise(delay);
211
-
212
- const linterLast = new NpmGroovyLint(npmGroovyLintConfig, {
213
- requestKey: requestKey
214
- });
215
- await linterLast.run();
216
-
217
- assert([0, 9].includes(linter1.status), `Linter 1 status is 9 or 0 (returned ${linter1.status}`);
218
- assert([0, 9].includes(linter2.status), `Linter 2 status is 9 or 0 (returned ${linter2.status}`);
219
- assert([0, 9].includes(linter3.status), `Linter 3 status is 9 or 0 (returned ${linter3.status}`);
220
- assert([0, 9].includes(linter4.status), `Linter 4 status is 9 or 0 (returned ${linter4.status}`);
221
- assert([0, 9].includes(linter5.status), `Linter 5 status is 9 or 0 (returned ${linter5.status}`);
222
- assert([0, 9].includes(linter6.status), `Linter 6 status is 9 or 0 (returned ${linter6.status}`);
223
- assert([0].includes(linterLast.status), `LinterLast status = 0 (returned ${linterLast.status}`);
224
- assert(
225
- [linter1.status, linter2.status, linter3.status, linter4.status, linter5.status, linter6.status].includes(9),
226
- `at least one response code is 9`
227
- );
228
- await Promise.all(linterProms);
229
- });
230
-
231
- it("(API:help) should show npm-groovy-lint help", async () => {
232
- const linter = await new NpmGroovyLint([process.execPath, "", "-h"], {}).run();
233
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
234
- assert(linter.outputString.includes("--verbose"), "--verbose is found in output text");
235
- });
236
-
237
- it("(API:help) should show npm-groovy-lint help option", async () => {
238
- const linter = await new NpmGroovyLint([process.execPath, "", "-h", "source"], {}).run();
239
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
240
- assert(linter.outputString.includes("-s, --source"), "npm-groovy-lint Help is displayed");
241
- });
242
-
243
- it("(API:help) should show npm-groovy-lint version", async () => {
244
- process.env.npm_package_version = ""; // NV: Do not use npm_package_version to have more code coverage :)
245
- const linter = await new NpmGroovyLint([process.execPath, "", "-v"], {}).run();
246
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
247
- const FindPackageJson = require("find-package-json");
248
- const finder = FindPackageJson(__dirname);
249
- const v = finder.next().value.version;
250
- assert(linter.outputString.includes(`npm-groovy-lint version ${v}`), `Provides version ${v}\nReturned outputString:\n${linter.outputString}`);
251
- assert(linter.outputString.includes(`CodeNarc version`), `Provides CodeNarc version\nReturned outputString:\n${linter.outputString}`);
252
- assert(linter.outputString.includes(`Groovy version`), `Provides CodeNarc version\nReturned outputString:\n${linter.outputString}`);
253
- });
254
-
255
- it("(API:help) should show codenarc help", async () => {
256
- const linter = await new NpmGroovyLint([process.execPath, "", "--codenarcargs", "-help"], {}).run();
257
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
258
- assert(linter.codeNarcStdOut.includes("where OPTIONS are zero or more command-line options"), "CodeNarc help is displayed");
259
- checkCodeNarcCallsCounter(1);
260
- });
261
-
262
- it("(API:Server) should kill running server", async () => {
263
- const linter = await new NpmGroovyLint([process.execPath, "", "--killserver", "--no-insight", "--verbose"], {
264
- verbose: true
265
- }).run();
266
-
267
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
268
- assert(linter.outputString.includes("CodeNarcServer terminated"), "CodeNarcServer has been terminated");
269
- checkCodeNarcCallsCounter(1);
270
- });
271
-
272
- it("(API:Server) should not succeed to kill running server", async () => {
273
- const linter = await new NpmGroovyLint([process.execPath, "", "--killserver", "--no-insight", "--verbose"], {
274
- verbose: true
275
- }).run();
276
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
277
- assert(linter.outputString.includes("CodeNarcServer was not running"), "CodeNarcServer not killed because not running");
278
- checkCodeNarcCallsCounter(1);
279
- });
280
-
281
- it("(API:source) override java executable", async () => {
282
- let javaPath;
283
- try {
284
- javaPath = which.sync("java");
285
- } catch (e) {
286
- console.log("Java not found: ignore test method");
287
- }
288
- if (javaPath) {
289
- console.log(`Java found: ${javaPath}`);
290
- const javaExec = javaPath;
291
- const javaOptions = "-Xms512m,-Xmx2g";
292
- const npmGroovyLintConfig = {
293
- path: "./lib/example/",
294
- files: "**/" + SAMPLE_FILE_SMALL,
295
- insight: false,
296
- javaexecutable: javaExec,
297
- javaoptions: javaOptions,
298
- output: "none"
299
- };
300
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
301
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
302
- }
303
- }).timeout(120000);
304
-
305
- it("(API:Server) should kill java override running server", async () => {
306
- let javaPath;
307
- try {
308
- javaPath = which.sync("java");
309
- } catch (e) {
310
- console.log("Java not found: ignore test method");
311
- }
312
- if (javaPath) {
313
- const linter = await new NpmGroovyLint([process.execPath, "", "--killserver", "--no-insight", "--verbose"], {
314
- verbose: true
315
- }).run();
316
-
317
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
318
- assert(linter.outputString.includes("CodeNarcServer terminated"), "CodeNarcServer has been terminated");
319
- checkCodeNarcCallsCounter(1);
320
- }
321
- });
322
- });
323
-
324
- function sleepPromise(ms) {
325
- return new Promise(resolve => setTimeout(resolve, ms));
326
- }