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.
Files changed (42) hide show
  1. package/CHANGELOG.md +24 -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.1.jar +0 -0
  23. package/lib/java/log4j-core-2.17.1.jar +0 -0
  24. package/lib/java/log4j-slf4j-impl-2.17.1.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
@@ -2,14 +2,6 @@
2
2
  ///////////////////////////////////////////////// COMMON LIBRARY /////////////////////////////////////////
3
3
  //////////////////////////////////////////////////////////////////////////////////////////////////////////
4
4
 
5
- @Grapes([
6
- @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'),
7
- @Grab(group='com.google.guava', module='guava', version='19.0'),
8
- @Grab(group='org.apache.commons', module='commons-lang3', version='3.7')
9
- ])
10
-
11
- import com.google.common.collect.Lists
12
-
13
5
  import groovy.io.FileType
14
6
  import groovy.json.JsonSlurper
15
7
  import groovy.time.TimeCategory
@@ -1,12 +1,6 @@
1
1
  import groovy.io.FileType
2
2
  import groovy.json.*
3
3
  import groovy.time.TimeCategory
4
- import static groovyx2.gpars.GParsPool.withPool
5
-
6
- def script = new GroovyScriptEngine( '.' ).with{
7
- loadScriptByName( 'Utils.groovy' ) ;
8
- }
9
- this.metaClass.mixin script
10
4
 
11
5
  def returnCode = 0
12
6
  Exception eThrow = null ;
@@ -1,11 +1,6 @@
1
1
  import groovy.json.*
2
2
  import java.security.SecureRandom
3
3
 
4
- def script = new GroovyScriptEngine( '.' ).with {
5
- loadScriptByName( 'Utils.groovy' )
6
- }
7
- this.metaClass.mixin script
8
-
9
4
  def returnCode = 0
10
5
  Exception eThrow = null
11
6
  try {
@@ -1,12 +1,6 @@
1
1
  import groovy.io.FileType
2
2
  import groovy.json.*
3
3
  import groovy.time.TimeCategory
4
- import static groovyx2.gpars.GParsPool.withPool
5
-
6
- def script = new GroovyScriptEngine( '.' ).with {
7
- loadScriptByName( 'Utils.groovy' )
8
- }
9
- this.metaClass.mixin script
10
4
 
11
5
  def returnCode = 0
12
6
  Exception eThrow = null
@@ -1,5 +1,3 @@
1
- #! /usr/bin/env node
2
-
3
1
  // Imports
4
2
  const fse = require("fs-extra");
5
3
  const cliProgress = require("cli-progress");
@@ -1,5 +1,3 @@
1
- #! /usr/bin/env node
2
-
3
1
  // Imports
4
2
  const debug = require("debug")("npm-groovy-lint");
5
3
  const os = require("os");
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "npm-groovy-lint",
3
- "version": "8.2.0",
3
+ "version": "9.3.0",
4
4
  "description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx,json}\" --tab-width 4 --print-width 150",
8
- "groovy:run-server-from-source": "npm run dev:kill-server && groovy -cp \"lib/java/CodeNarc-2.0.0.jar;lib/java/groovy/lib/groovy-3.0.5.jar;lib/java/groovy/lib/groovy-templates-3.0.5.jar;lib/java/groovy/lib/groovy-xml-3.0.5.jar;lib/java/groovy/lib/groovy-json-3.0.5.jar;lib/java/groovy/lib/groovy-ant-3.0.5.jar;lib/java/groovy/lib/ant-1.10.8.jar;lib/java/groovy/lib/ant-launcher-1.10.8.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.13.0.jar;lib/java/log4j-api-2.13.0.jar;lib/java/log4j-core-2.13.0.jar;lib/java/gmetrics-1.1.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
8
+ "groovy:run-server-from-source": "npm run dev:kill-server && groovy -cp \"lib/java/CodeNarc-2.2.0.jar;lib/java/groovy/lib/groovy-3.0.9.jar;lib/java/groovy/lib/groovy-templates-3.0.9.jar;lib/java/groovy/lib/groovy-xml-3.0.9.jar;lib/java/groovy/lib/groovy-json-3.0.9.jar;lib/java/groovy/lib/groovy-ant-3.0.9.jar;lib/java/groovy/lib/ant-1.10.11.jar;lib/java/groovy/lib/ant-launcher-1.10.11.jar;lib/java/slf4j-api-1.7.9.jar;lib/java/log4j-slf4j-impl-2.17.1.jar;lib/java/log4j-api-2.17.1.jar;lib/java/log4j-core-2.17.1.jar;lib/java/gmetrics-1.1.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
9
9
  "groovy:build": "npm run dev:kill-server && groovyc -cp \"./lib/java*\" --encoding utf-8 ./groovy/src/main/com/nvuillam/CodeNarcServer.groovy -d ./tmp && cd ./tmp && jar -cvfm ./../lib/java/CodeNarcServer.jar ./../MANIFEST.txt ./com/nvuillam/*.class && cd ..",
10
- "test": "npm run dev:kill-server && mocha \"lib/test/**/*.test.js\"",
10
+ "test": "npm run dev:kill-server && mocha \"test/**/*.test.js\"",
11
11
  "test:coverage": "nyc npm run test",
12
- "test:debug": "npm run dev:kill-server && mocha --reporter spec --inspect-brk \"lib/test/**/*.test.js\"",
12
+ "test:debug": "npm run dev:kill-server && mocha --reporter spec --inspect-brk \"test/**/*.test.js\"",
13
13
  "build": "node script-build-config-all.js && cp -f README.md docs/index.md && cp -f CHANGELOG.md docs/CHANGELOG.md",
14
14
  "dev:kill-server": "npm-groovy-lint --killserver",
15
15
  "dev:lint-install-local": "npm run dev:kill-server && npm run lint:fix && npm link --force",
@@ -44,9 +44,10 @@
44
44
  "npm-groovy-lint": "lib/index.js"
45
45
  },
46
46
  "dependencies": {
47
- "amplitude": "^5.1.2",
47
+ "amplitude": "^5.1.6",
48
48
  "ansi-colors": "^4.1.1",
49
49
  "axios": "^0.21.1",
50
+ "chalk": "^4.1.2",
50
51
  "cli-progress": "^3.6.0",
51
52
  "debug": "^4.1.1",
52
53
  "decode-html": "^2.0.0",
@@ -63,16 +64,17 @@
63
64
  "uuid": "^8.2.0"
64
65
  },
65
66
  "devDependencies": {
66
- "babel-eslint": "^10.0.3",
67
+ "@babel/core": "^7.16.0",
68
+ "@babel/eslint-parser": "^7.16.3",
67
69
  "diff": "^4.0.2",
68
- "eslint": "^6.8.0",
69
- "eslint-config-standard": "^14.1.0",
70
- "eslint-plugin-import": "^2.20.1",
71
- "eslint-plugin-node": "^11.0.0",
72
- "eslint-plugin-promise": "^4.2.1",
73
- "eslint-plugin-standard": "^4.0.1",
70
+ "eslint": "^8.2.0",
71
+ "eslint-config-standard": "^16.0.3",
72
+ "eslint-plugin-import": "^2.25.3",
73
+ "eslint-plugin-node": "^11.1.0",
74
+ "eslint-plugin-promise": "^5.1.1",
75
+ "eslint-plugin-standard": "^5.0.0",
74
76
  "mocha": "^7.0.1",
75
- "nyc": "^15.0.0-beta.3",
77
+ "nyc": "^15.1.0",
76
78
  "prettier": "1.19.1",
77
79
  "rimraf": "^3.0.2",
78
80
  "which": "^2.0.2"
@@ -82,7 +84,7 @@
82
84
  },
83
85
  "mocha": {
84
86
  "require": [
85
- "lib/test/helpers/init.js"
87
+ "test/helpers/init.js"
86
88
  ],
87
89
  "watch-extensions": [
88
90
  "js"
Binary file
Binary file
Binary file
@@ -1,92 +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
-
7
- const { SAMPLE_FILE_SMALL_PATH } = require("./helpers/common");
8
-
9
- describe("Errors", function() {
10
- it("(API:source) should trigger a parse options error", async () => {
11
- const prevFileContent = fse.readFileSync("./lib/example/SampleFile.groovy").toString();
12
- const npmGroovyLintConfig = {
13
- source: prevFileContent,
14
- someUnknownParam: "lelamanul"
15
- };
16
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
17
-
18
- assert(linter.status === 2, `Linter status is 2 (${linter.status} returned)`);
19
- assert(linter.error.msg.includes("Invalid option"), "Invalid option detected");
20
- });
21
-
22
- it("(API:source) should trigger a loglevel failon consistency error", async () => {
23
- const prevFileContent = fse.readFileSync("./lib/example/SampleFile.groovy").toString();
24
- const npmGroovyLintConfig = {
25
- source: prevFileContent,
26
- failon: "warning",
27
- loglevel: "error"
28
- };
29
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
30
-
31
- assert(linter.status === 2, `Linter status is 2 (${linter.status} returned)`);
32
- assert(linter.error.msg.includes("failon option"), "failon + loglevel options consistency error detected");
33
- });
34
-
35
- it("(API:source) should trigger a codenarc error", async () => {
36
- const npmGroovyLintConfig = {
37
- path: "/not/existing/path",
38
- output: "txt",
39
- verbose: true
40
- };
41
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
42
-
43
- assert(linter.status === 2, `Linter status is 2 (${linter.status} returned)`);
44
- assert(
45
- linter.error && linter.error.msg.includes("java.io.FileNotFoundException"),
46
- `FileNotFoundException returned by CodeNarc (error: ${linter.error.msg})`
47
- );
48
- });
49
-
50
- it("(API:source) should trigger a codenarc error (--noserver)", async () => {
51
- const npmGroovyLintConfig = {
52
- path: "/not/existing/path",
53
- noserver: true
54
- };
55
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
56
-
57
- assert(linter.status === 2, `Linter status is 2 (${linter.status} returned)`);
58
- assert(
59
- linter.error && linter.error.msg.includes("java.io.FileNotFoundException"),
60
- `FileNotFoundException returned by CodeNarc (error: ${linter.error.msg})`
61
- );
62
- });
63
-
64
- it("(API:source) should trigger a fix function error", async () => {
65
- const prevFileContent = fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString();
66
- const npmGroovyLintConfig = {
67
- source: prevFileContent,
68
- fix: true,
69
- fixrules: "TriggerTestError",
70
- insight: false,
71
- output: "txt",
72
- verbose: true
73
- };
74
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
75
-
76
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
77
- });
78
-
79
- it("(API:source) should detect and display a parse error", async () => {
80
- const npmGroovyLintConfig = {
81
- failon: "error",
82
- path: "./lib/example/test",
83
- files: "**/groovy-bad.groovy",
84
- insight: false,
85
- output: "txt"
86
- };
87
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
88
-
89
- assert(linter.status === 1, `Linter status is 1 (${linter.status} returned)`);
90
- assert(linter.outputString.includes("NglParseError"), "Parse error has been detected");
91
- });
92
- });
@@ -1,84 +0,0 @@
1
- #! /usr/bin/env node
2
- let assert = require("assert");
3
- const os = require("os");
4
- const fse = require("fs-extra");
5
- const jsdiff = require("diff");
6
-
7
- const NPM_GROOVY_LINT = "npm-groovy-lint ";
8
- const startPath = "./lib/example/";
9
- const SAMPLE_FILE_BIG = "SampleFile.groovy";
10
- const SAMPLE_FILE_BIG_PATH = startPath + SAMPLE_FILE_BIG;
11
- const SAMPLE_FILE_SMALL = "SampleFileSmall.groovy";
12
- const SAMPLE_FILE_SMALL_FORMAT = "SampleFileSmallFormatted.txt";
13
- const SAMPLE_FILE_SMALL_FIX = "SampleFileSmallFixed.txt";
14
- const SAMPLE_FILE_SMALL_PATH = startPath + SAMPLE_FILE_SMALL;
15
- const SAMPLE_FILE_PARSE_ERROR = "WithParseError.groovy";
16
- const SAMPLE_FILE_PARSE_ERROR_PATH = startPath + SAMPLE_FILE_PARSE_ERROR;
17
- const SAMPLE_RULESET_1 = "RuleSet-1.groovy";
18
- const SAMPLE_RULESET_1_PATH = startPath + SAMPLE_RULESET_1;
19
- const SAMPLE_RULESET_2 = "RuleSet-2.groovy";
20
- const SAMPLE_RULESET_2_PATH = startPath + SAMPLE_RULESET_2;
21
-
22
- // Reset codeNarcCallsCounter before each test
23
- const beforeEachTestCase = function() {
24
- globalThis.codeNarcCallsCounter = 0;
25
- globalThis.codeNarcCalls = [];
26
- };
27
-
28
- // Check counter of calls to CodeNarc
29
- const checkCodeNarcCallsCounter = expectedNb => {
30
- assert(
31
- expectedNb === globalThis.codeNarcCallsCounter,
32
- `Number of calls to codeNarc is wrong: ${expectedNb} expected but ${
33
- globalThis.codeNarcCallsCounter
34
- } returned.\nCodeNarc calls: \n${JSON.stringify(globalThis.codeNarcCalls, null, 2)}`
35
- );
36
- };
37
-
38
- // Copy files in temp directory to not update the package files
39
- async function copyFilesInTmpDir() {
40
- const rootTmpDir =
41
- process.platform.includes("linux") || process.platform.includes("darwin") // Linux or mac
42
- ? "./tmptest"
43
- : os.tmpdir(); // Windows / other
44
- const tmpDir = rootTmpDir + "/" + ("tmpGroovyLintTest_" + Math.random()).replace(".", "");
45
- await fse.ensureDir(tmpDir, { mode: "0777" });
46
- await fse.copy("./lib/example", tmpDir);
47
- console.info("GroovyLint: Copied ./lib/example into " + tmpDir);
48
- return tmpDir;
49
- }
50
-
51
- // Get diff between 2 strings
52
- function getDiff(expected, afterUpdate, beforeUpdate) {
53
- const diff = jsdiff.diffChars(expected, afterUpdate);
54
- const effectiveDiffs = diff.filter(item => item.added || item.removed);
55
- if (effectiveDiffs.length > 0) {
56
- console.error("BeforeFix: \n" + beforeUpdate);
57
- console.error("AfterFix: \n" + afterUpdate);
58
- console.error("Expected: \n" + expected);
59
- } else {
60
- console.info("BeforeFix: \n" + beforeUpdate);
61
- console.info("Verified: \n" + afterUpdate);
62
- }
63
- return effectiveDiffs;
64
- }
65
-
66
- module.exports = {
67
- NPM_GROOVY_LINT,
68
- SAMPLE_FILE_BIG,
69
- SAMPLE_FILE_SMALL,
70
- SAMPLE_FILE_SMALL_FORMAT,
71
- SAMPLE_FILE_SMALL_FIX,
72
- SAMPLE_FILE_BIG_PATH,
73
- SAMPLE_FILE_SMALL_PATH,
74
- SAMPLE_FILE_PARSE_ERROR,
75
- SAMPLE_FILE_PARSE_ERROR_PATH,
76
- SAMPLE_RULESET_1,
77
- SAMPLE_RULESET_1_PATH,
78
- SAMPLE_RULESET_2,
79
- SAMPLE_RULESET_2_PATH,
80
- beforeEachTestCase,
81
- checkCodeNarcCallsCounter,
82
- copyFilesInTmpDir,
83
- getDiff
84
- };
@@ -1,29 +0,0 @@
1
- #! /usr/bin/env node
2
- "use strict";
3
-
4
- //const NpmGroovyLint = require("../../groovy-lint.js");
5
-
6
- console.log("npm run test initialized");
7
- // Activate debug log if we are in debug mode
8
- const debug = typeof v8debug === "object" || /--debug|--inspect|--inspect-brk/.test(process.execArgv.join(" "));
9
- if (debug) {
10
- require("debug").enable("npm-groovy-lint");
11
- require("debug").enable("java-caller");
12
- }
13
- // Reinitialize java-caller cache
14
- globalThis.NPM_JAVA_CALLER_IS_INITIALIZED = false;
15
- globalThis.NPM_GROOVY_LINT_TEST = true;
16
- /*
17
- // Kill server if already running
18
- (async () => {
19
- try {
20
- await new NpmGroovyLint({
21
- killserver: true,
22
- insight: false,
23
- verbose: true
24
- }).run();
25
- } catch (err) {
26
- console.error("Error while killing running server");
27
- }
28
- })();
29
- */
@@ -1,221 +0,0 @@
1
- #! /usr/bin/env node
2
- "use strict";
3
- const NpmGroovyLint = require("../groovy-lint.js");
4
- let assert = require("assert");
5
- const c = require("ansi-colors");
6
- const fse = require("fs-extra");
7
- const path = require("path");
8
- const {
9
- beforeEachTestCase,
10
- checkCodeNarcCallsCounter,
11
- SAMPLE_FILE_PARSE_ERROR_PATH,
12
- SAMPLE_FILE_SMALL,
13
- SAMPLE_FILE_SMALL_PATH,
14
- SAMPLE_RULESET_1_PATH,
15
- SAMPLE_RULESET_2_PATH
16
- } = require("./helpers/common");
17
-
18
- describe("Lint with API", () => {
19
- beforeEach(beforeEachTestCase);
20
-
21
- it("(API:file) should generate text console output ans stats", async () => {
22
- const linter = await new NpmGroovyLint([process.execPath, "", "--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--verbose"], {
23
- verbose: true
24
- }).run();
25
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
26
- assert(linter.outputString.includes("warning"), "Output string contains warning");
27
- assert(linter.lintResult.summary.totalFoundWarningNumber > 0, "Warnings found");
28
- assert(linter.lintResult.summary.totalFoundInfoNumber > 0, "Infos found");
29
- checkCodeNarcCallsCounter(1);
30
- });
31
-
32
- it("(API:file) should generate text console output with loglevel=warning", async () => {
33
- const linter = await new NpmGroovyLint(
34
- [process.execPath, "", "--path", '"lib/example"', "--files", "**/" + SAMPLE_FILE_SMALL, "--loglevel", "warning", "--verbose"],
35
- {
36
- verbose: true
37
- }
38
- ).run();
39
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
40
- assert(linter.outputString.includes("warning"), "Output string contains warning");
41
- assert(!linter.outputString.includes("info"), "Output string should not contain info");
42
- assert(linter.lintResult.summary.totalFoundWarningNumber > 0, "Warnings found");
43
- checkCodeNarcCallsCounter(1);
44
- });
45
-
46
- it("(API:file) should generate json output with rules", async () => {
47
- const linter = await new NpmGroovyLint(
48
- [
49
- process.execPath,
50
- "",
51
- "--path",
52
- '"lib/example"',
53
- "--files",
54
- "**/" + SAMPLE_FILE_SMALL,
55
- "--output",
56
- "json",
57
- "--no-insight",
58
- "--loglevel",
59
- "warning"
60
- ],
61
- {}
62
- ).run();
63
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
64
- assert(linter.outputString.includes(`"totalFoundWarningNumber":`), "Property totalFoundWarningNumber is in result");
65
- assert(linter.lintResult.summary.totalFoundWarningNumber > 0, "Warnings found");
66
- checkCodeNarcCallsCounter(1);
67
- });
68
-
69
- it("(API:file) should generate codenarc HTML file report", async () => {
70
- const reportFileName = path.resolve("./tmp/ReportTestCodenarc.html");
71
- const linter = await new NpmGroovyLint(
72
- [process.execPath, "", "--path", "./lib/example", "--files", "**/" + SAMPLE_FILE_SMALL, "--no-insight", "--output", reportFileName],
73
- {}
74
- ).run();
75
-
76
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
77
- assert(fse.existsSync(reportFileName), `CodeNarc HTML report generated at ${reportFileName}`);
78
- fse.removeSync(reportFileName);
79
- checkCodeNarcCallsCounter(1);
80
- });
81
-
82
- it("(API:file) should generate codenarc XML file report", async () => {
83
- const reportFileName = path.resolve("./tmp/ReportTestCodenarc.xml");
84
- const linter = await new NpmGroovyLint(
85
- [process.execPath, "", "--path", "lib/example", "--files", "**/" + SAMPLE_FILE_SMALL, "--no-insight", "--output", reportFileName],
86
- {}
87
- ).run();
88
-
89
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
90
- assert(fse.existsSync(reportFileName), `CodeNarc XML report generated at ${path.resolve(reportFileName)}`);
91
- fse.removeSync(reportFileName);
92
- checkCodeNarcCallsCounter(1);
93
- });
94
-
95
- it("(API:file) should use --codenarcargs to generate XML report", async () => {
96
- const reportFileName = path.resolve("./tmp/ReportTestCodenarc.xml");
97
- const linter = await new NpmGroovyLint(
98
- [
99
- process.execPath,
100
- "",
101
- "--codenarcargs",
102
- `-basedir="${path.resolve("lib/example")}"`,
103
- '-title="TestTitleCodenarc"',
104
- "-maxPriority1Violations=0",
105
- `-report="xml:${reportFileName}"`
106
- ],
107
- {}
108
- ).run();
109
-
110
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
111
- assert(fse.existsSync(reportFileName), `XML HTML report generated at ${path.resolve(reportFileName)}`);
112
- fse.removeSync(reportFileName);
113
- checkCodeNarcCallsCounter(1);
114
- });
115
-
116
- it("(API:file) should run on a Jenkinsfile", async () => {
117
- const linter = await new NpmGroovyLint(
118
- [process.execPath, "", "--path", '"lib/example"', "-f", "**/Jenkinsfile", "-c", "recommended-jenkinsfile", "--no-insight", "--verbose"],
119
- {
120
- verbose: true
121
- }
122
- ).run();
123
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
124
- assert(linter.outputString.includes("warning"), "Output string contains warning");
125
- assert(linter.lintResult.summary.totalFoundWarningNumber > 0, "Warnings found");
126
- assert(linter.lintResult.summary.totalFoundInfoNumber > 0, "Infos found");
127
- checkCodeNarcCallsCounter(1);
128
- });
129
-
130
- it("(API:files) should ignore fake_node_modules pattern", async () => {
131
- const lintedFilesNb = 10;
132
- const npmGroovyLintConfig = {
133
- files: "**/*.groovy",
134
- ignorepattern: "**/fake_node_modules/**",
135
- output: "txt",
136
- insight: false,
137
- verbose: true
138
- };
139
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
140
- assert(!linter.outputString.includes(`ToIgnore.groovy`), "ToIgnore.groovy has been ignored");
141
- assert(
142
- linter.outputString.includes(`npm-groovy-lint results in ${c.bold(lintedFilesNb)} linted files`),
143
- `Number of linted files is displayed in summary: ${c.bold(lintedFilesNb)}`
144
- );
145
- });
146
-
147
- it("(API:source) should run with source only (no parsing)", async () => {
148
- const npmGroovyLintConfig = {
149
- source: fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString(),
150
- sourcefilepath: SAMPLE_FILE_SMALL_PATH,
151
- insight: false,
152
- output: "txt",
153
- verbose: true
154
- };
155
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
156
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
157
- assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
158
- checkCodeNarcCallsCounter(1);
159
- });
160
-
161
- it("(API:source) should run with CodeNarc ruleset file", async () => {
162
- const npmGroovyLintConfig = {
163
- source: fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString(),
164
- sourcefilepath: SAMPLE_FILE_SMALL_PATH,
165
- rulesets: `${SAMPLE_RULESET_1_PATH},${SAMPLE_RULESET_2_PATH}`,
166
- output: "txt",
167
- insight: false,
168
- parse: true,
169
- verbose: true
170
- };
171
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
172
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
173
- assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
174
- checkCodeNarcCallsCounter(1);
175
- });
176
-
177
- it("(API:source) should run with source only (parse success)", async () => {
178
- const npmGroovyLintConfig = {
179
- source: fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString(),
180
- sourcefilepath: SAMPLE_FILE_SMALL_PATH,
181
- output: "txt",
182
- insight: false,
183
- parse: true,
184
- verbose: true
185
- };
186
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
187
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
188
- assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
189
- checkCodeNarcCallsCounter(1);
190
- });
191
-
192
- it("(API:source) should run with source only (parse error)", async () => {
193
- const npmGroovyLintConfig = {
194
- source: fse.readFileSync(SAMPLE_FILE_PARSE_ERROR_PATH).toString(),
195
- sourcefilepath: SAMPLE_FILE_PARSE_ERROR_PATH,
196
- output: "txt",
197
- insight: false,
198
- verbose: true
199
- };
200
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
201
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
202
- assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
203
- assert(linter.outputString.includes("NglParseError"), "Parse error has been detected");
204
- checkCodeNarcCallsCounter(1);
205
- });
206
-
207
- it("(API:source) should run without CodeNarc Server", async () => {
208
- const npmGroovyLintConfig = {
209
- source: fse.readFileSync(SAMPLE_FILE_SMALL_PATH).toString(),
210
- sourcefilepath: SAMPLE_FILE_SMALL_PATH,
211
- noserver: true,
212
- output: "none",
213
- insight: false,
214
- verbose: true
215
- };
216
- const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
217
- assert(linter.status === 0, `Linter status is 0 (${linter.status} returned)`);
218
- assert(linter.lintResult.files[0].errors.length > 0, "Errors have been found");
219
- checkCodeNarcCallsCounter(1);
220
- });
221
- });
@@ -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_FIX, NPM_GROOVY_LINT } = require("./helpers/common");
10
-
11
- describe("Lint & fix with EXE", function() {
12
- beforeEach(beforeEachTestCase);
13
-
14
- it("(API:file) should lint and fix 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
- "--fix",
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_FIX).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
- });