npm-groovy-lint 9.5.0 → 10.0.2
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 +40 -2
- package/README.md +29 -3
- package/lib/.groovylintrc-all.json +0 -1
- package/lib/.groovylintrc-format.json +2 -0
- package/lib/codenarc-caller.js +7 -3
- package/lib/codenarc-factory.js +103 -16
- package/lib/example/RuleSet-All.groovy +413 -417
- package/lib/example/SampleFileSmall.groovy +3 -3
- package/lib/example/SampleFileSmallFixed.txt +4 -4
- package/lib/example/SampleFileSmallFormatted.txt +4 -4
- package/lib/groovy-lint-rules.js +2 -0
- package/lib/groovy-lint.js +3 -1
- package/lib/index.js +5 -1
- package/lib/java/CodeNarc-3.1.0.jar +0 -0
- package/lib/java/CodeNarcServer.jar +0 -0
- package/lib/java/GMetrics-2.1.0.jar +0 -0
- package/lib/java/{log4j-api-2.17.1.jar → log4j-api-2.18.0.jar} +0 -0
- package/lib/java/{log4j-core-2.17.1.jar → log4j-core-2.18.0.jar} +0 -0
- package/lib/java/{log4j-slf4j-impl-2.17.1.jar → log4j-slf4j-impl-2.18.0.jar} +0 -0
- package/lib/options.js +28 -14
- package/lib/output.js +1 -3
- package/lib/rules/DuplicateNumberLiteral.js +21 -0
- package/lib/rules/DuplicateStringLiteral.js +21 -0
- package/lib/rules/MethodParameterTypeRequired.js +21 -0
- package/lib/rules/MisorderedStaticImports.js +2 -2
- package/lib/rules/NoDef.js +14 -0
- package/lib/rules/SimpleDateFormatMissingLocale.js +14 -0
- package/lib/rules/SpaceAfterMethodCallName.js +30 -0
- package/lib/rules/SpaceInsideParentheses.js +73 -0
- package/lib/rules/UnnecessaryPublicModifier.js +13 -0
- package/lib/rules/VariableTypeRequired.js +36 -0
- package/lib/utils.js +2 -2
- package/package.json +5 -8
- package/lib/java/CodeNarc-2.2.0.jar +0 -0
- package/lib/java/gmetrics-1.1.jar +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,13 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## [10.0.2] 2022-08-15
|
|
6
|
+
|
|
7
|
+
- Fix error when absolute files sent as positional arguments on a linux system ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
|
8
|
+
- Improve performances by calculating the longest command directory to send as base path to CodeNarc
|
|
9
|
+
|
|
10
|
+
## [10.0.1] 2022-08-14
|
|
11
|
+
|
|
12
|
+
- Fix error when files sent as positional arguments ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
|
13
|
+
|
|
14
|
+
## [10.0.0] 2022-08-13
|
|
15
|
+
|
|
16
|
+
- Core
|
|
17
|
+
- Upgrade to [CodeNarc v3.1.0](https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.md#version-310----jun-2022)
|
|
18
|
+
- Accept list of directories / files as arguments (`--path` and `--files` become deprecated but are still usable)
|
|
19
|
+
- Examples
|
|
20
|
+
- Multiple files: `npm-groovy-lint path/to/file1.groovy path/to/file2.groovy`
|
|
21
|
+
- Directory: `npm groovy-lint path/to`
|
|
22
|
+
- Single file: `npm-groovy-lint Jenkinsfile`
|
|
23
|
+
- Ant pattern(s): `npm-groovy-lint path/to/**/*.groovy`
|
|
24
|
+
- Upgrade npm dependencies
|
|
25
|
+
- CI: Upgrade [MegaLinter](https://oxsecurity.github.io/megalinter/latest/) to v6
|
|
26
|
+
- Test classes for collecting error ranges
|
|
27
|
+
|
|
28
|
+
- New error ranges rules
|
|
29
|
+
- DuplicateNumberLiteral
|
|
30
|
+
- DuplicateStringLiteral
|
|
31
|
+
- MethodParameterTypeRequired
|
|
32
|
+
- NoDef
|
|
33
|
+
- SimpleDateFormatMissingLocale
|
|
34
|
+
- SpaceInsideParenthesis
|
|
35
|
+
- UnnecessaryPublicModifier
|
|
36
|
+
- VariableTypeRequired
|
|
37
|
+
|
|
38
|
+
- New fix rules
|
|
39
|
+
- SpaceAfterMethodCallName
|
|
40
|
+
- SpaceInsideParentheses
|
|
41
|
+
|
|
42
|
+
- Bug Fixes
|
|
43
|
+
- Wrongly calculated ranges are no more returned
|
|
6
44
|
|
|
7
45
|
## [9.5.0] 2022-04-12
|
|
8
46
|
|
|
9
47
|
- Disable Amplitude anonymous stats by default (use `--insight` to enable them)
|
|
10
48
|
|
|
11
|
-
## [9.4.1] 2022-01-
|
|
49
|
+
## [9.4.1] 2022-01-12
|
|
12
50
|
|
|
13
51
|
- Upgrade node-sarif-builder to 2.0.1 and send npm-groovy-lint version in SARIF logs
|
|
14
52
|
- New range detection for rules:
|
package/README.md
CHANGED
|
@@ -40,13 +40,13 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
|
|
|
40
40
|
## Usage
|
|
41
41
|
|
|
42
42
|
```shell
|
|
43
|
-
npm-groovy-lint OPTIONS
|
|
43
|
+
npm-groovy-lint [OPTIONS] [FILES|PATH|PATTERN]
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
See [examples](#example-calls)
|
|
47
|
+
|
|
46
48
|
| Parameter | Type | Description |
|
|
47
49
|
|-------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
48
|
-
| -p<br/> --path | String | Directory containing the files to lint<br/> Example: `./path/to/my/groovy/files` |
|
|
49
|
-
| -f<br/> --files | String | Comma-separated list of Ant-style file patterns specifying files that must be included.<br/> Default: `"**/*.groovy,**/Jenkinsfile,**/*.gradle"`<br/>Examples:<br/> - `"**/Jenkinsfile"`<br/> - `"**/*.groovy"`<br/> - `"**/*.gradle"`<br/> - `"**/mySingleFile.groovy"` |
|
|
50
50
|
| -o<br/> --output | String | Output format (txt,json,sarif,html,xml), or path to a file with one of these extensions<br/> Default: `txt`<br/> Examples:<br/> - `"txt"`<br/> - `"json"`<br/> - `"./logs/myLintResults.txt"`<br/> - `"./logs/myLintResults.sarif"`<br/> - `"./logs/myLintResults.html"`<br/> - `"./logs/myLintResults.xml"` |
|
|
51
51
|
| -l<br/> --loglevel | String | Log level (error,warning or info)<br/>Default: info |
|
|
52
52
|
| --failon | String | Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Each failure level includes the more critical ones. |
|
|
@@ -69,6 +69,8 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
|
|
|
69
69
|
| --codenarcargs | String | Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored)<br/> Doc: <http://codenarc.github.io/CodeNarc/codenarc-command-line.html><br/> Example: `npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml` |
|
|
70
70
|
| -h<br/> --help | Boolean | Show help (npm-groovy-lint -h OPTIONNAME to see option detail with examples) |
|
|
71
71
|
| -v<br/> --version | Boolean | Show npm-groovy-lint version (with CodeNarc version) |
|
|
72
|
+
| -p<br/> --path | String | (DEPRECATED) Directory containing the files to lint<br/> Example: `./path/to/my/groovy/files` |
|
|
73
|
+
| -f<br/> --files | String | (DEPRECATED) Comma-separated list of Ant-style file patterns specifying files that must be included.<br/> Default: `"**/*.groovy,**/Jenkinsfile,**/*.gradle"`<br/>Examples:<br/> - `"**/Jenkinsfile"`<br/> - `"**/*.groovy"`<br/> - `"**/*.gradle"`<br/> - `"**/mySingleFile.groovy"` |
|
|
72
74
|
|
|
73
75
|
## Installation
|
|
74
76
|
|
|
@@ -145,6 +147,30 @@ OR
|
|
|
145
147
|
|
|
146
148
|
## Example calls
|
|
147
149
|
|
|
150
|
+
- Lint a file
|
|
151
|
+
|
|
152
|
+
```shell
|
|
153
|
+
npm-groovy-lint path/to/my/groovy/file.groovy
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- Lint multiple files
|
|
157
|
+
|
|
158
|
+
```shell
|
|
159
|
+
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- Lint directory
|
|
163
|
+
|
|
164
|
+
```shell
|
|
165
|
+
npm-groovy-lint path/to/my/groovy
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
- Lint pattern
|
|
169
|
+
|
|
170
|
+
```shell
|
|
171
|
+
npm-groovy-lint path/to/my/groovy/*.groovy
|
|
172
|
+
```
|
|
173
|
+
|
|
148
174
|
- Lint groovy with JSON output
|
|
149
175
|
|
|
150
176
|
```shell
|
|
@@ -380,7 +380,6 @@
|
|
|
380
380
|
"unnecessary.UnnecessarySemicolon": {},
|
|
381
381
|
"unnecessary.UnnecessarySetter": {},
|
|
382
382
|
"unnecessary.UnnecessaryStringInstantiation": {},
|
|
383
|
-
"unnecessary.UnnecessarySubstring": {},
|
|
384
383
|
"unnecessary.UnnecessaryTernaryExpression": {},
|
|
385
384
|
"unnecessary.UnnecessaryToString": {},
|
|
386
385
|
"unnecessary.UnnecessaryTransientModifier": {},
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"formatting.SpaceAfterComma": {},
|
|
30
30
|
"formatting.SpaceAfterFor": {},
|
|
31
31
|
"formatting.SpaceAfterIf": {},
|
|
32
|
+
"formatting.SpaceAfterMethodCallName": {},
|
|
32
33
|
"formatting.SpaceAfterOpeningBrace": {},
|
|
33
34
|
"formatting.SpaceAfterSemicolon": {},
|
|
34
35
|
"formatting.SpaceAfterSwitch": {},
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"formatting.SpaceAroundOperator": {},
|
|
39
40
|
"formatting.SpaceBeforeClosingBrace": {},
|
|
40
41
|
"formatting.SpaceBeforeOpeningBrace": {},
|
|
42
|
+
"formatting.SpaceInsideParentheses": {},
|
|
41
43
|
"formatting.TrailingWhitespace": {},
|
|
42
44
|
"unnecessary.UnnecessaryGString": {},
|
|
43
45
|
"unnecessary.UnnecessarySemicolon": {}
|
package/lib/codenarc-caller.js
CHANGED
|
@@ -39,7 +39,7 @@ class CodeNarcCaller {
|
|
|
39
39
|
rootPath: __dirname,
|
|
40
40
|
mainClass: "org.codenarc.CodeNarc",
|
|
41
41
|
classPath:
|
|
42
|
-
"java/CodeNarc-
|
|
42
|
+
"java/CodeNarc-3.1.0.jar:java/groovy/lib/groovy-3.0.9.jar:java/groovy/lib/groovy-templates-3.0.9.jar:java/groovy/lib/groovy-xml-3.0.9.jar:java/groovy/lib/groovy-json-3.0.9.jar:java/groovy/lib/groovy-ant-3.0.9.jar:java/groovy/lib/ant-1.10.11.jar:java/groovy/lib/ant-launcher-1.10.11.jar:java/slf4j-api-1.7.9.jar:java/log4j-slf4j-impl-2.18.0.jar:java/log4j-api-2.18.0.jar:java/log4j-core-2.18.0.jar:java/GMetrics-2.1.0.jar:java/*"
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
|
|
@@ -60,7 +60,10 @@ class CodeNarcCaller {
|
|
|
60
60
|
// Remove "" around values because they won't get thru system command line parser
|
|
61
61
|
const codeNarcArgsForServer = this.codenarcArgs.map(codeNarcArg => {
|
|
62
62
|
if (codeNarcArg.includes('="') || codeNarcArg.includes(':"')) {
|
|
63
|
-
codeNarcArg = codeNarcArg
|
|
63
|
+
codeNarcArg = codeNarcArg
|
|
64
|
+
.replace('="', "=")
|
|
65
|
+
.replace(':"', ":")
|
|
66
|
+
.replace(/ /g, "%20");
|
|
64
67
|
codeNarcArg = codeNarcArg.substring(0, codeNarcArg.length - 1);
|
|
65
68
|
}
|
|
66
69
|
return codeNarcArg;
|
|
@@ -76,7 +79,8 @@ class CodeNarcCaller {
|
|
|
76
79
|
codeNarcIncludes: this.execOpts.codeNarcIncludes,
|
|
77
80
|
codeNarcExcludes: this.execOpts.codeNarcExcludes,
|
|
78
81
|
parse: this.options.parse !== false && this.execOpts.onlyCodeNarc === false ? true : false,
|
|
79
|
-
file: this.execOpts.groovyFileName
|
|
82
|
+
file: this.execOpts.groovyFileName || null,
|
|
83
|
+
fileList: this.execOpts.inputFileList || null,
|
|
80
84
|
requestKey: this.execOpts.requestKey || null
|
|
81
85
|
},
|
|
82
86
|
timeout: 600000
|
package/lib/codenarc-factory.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
const debug = require("debug")("npm-groovy-lint");
|
|
5
|
+
const commondir = require("commondir");
|
|
5
6
|
const fs = require("fs-extra");
|
|
6
7
|
const os = require("os");
|
|
7
8
|
const path = require("path");
|
|
@@ -18,6 +19,8 @@ const npmGroovyLintRules = getNpmGroovyLintRules();
|
|
|
18
19
|
const CODENARC_TMP_FILENAME_BASE = "codeNarcTmpDir_";
|
|
19
20
|
const CODENARC_WWW_BASE = "https://codenarc.github.io/CodeNarc";
|
|
20
21
|
|
|
22
|
+
const defaultFilesPattern = ["*.groovy", "*.gvy", "Jenkinsfile", "*.gradle", "*.nf"];
|
|
23
|
+
|
|
21
24
|
// Convert NPM-groovy-lint into codeNarc arguments
|
|
22
25
|
// Create temporary files if necessary
|
|
23
26
|
async function prepareCodeNarcCall(options) {
|
|
@@ -25,6 +28,7 @@ async function prepareCodeNarcCall(options) {
|
|
|
25
28
|
|
|
26
29
|
let cnPath = options.path;
|
|
27
30
|
let cnFiles = options.files;
|
|
31
|
+
const positionalArgs = options._ || [];
|
|
28
32
|
|
|
29
33
|
// If source option, create a temporary Groovy file
|
|
30
34
|
if (options.source) {
|
|
@@ -52,16 +56,16 @@ async function prepareCodeNarcCall(options) {
|
|
|
52
56
|
|
|
53
57
|
// Define base directory
|
|
54
58
|
const baseBefore = (cnPath !== "." && cnPath.startsWith("/")) || cnPath.includes(":/") || cnPath.includes(":\\") ? "" : process.cwd() + "/";
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
const codeNarcBaseDir = positionalArgs.length > 0 ?
|
|
60
|
+
(await getCodeNarcBaseDirFromFiles(positionalArgs)) :
|
|
61
|
+
cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") :
|
|
62
|
+
process.cwd();
|
|
63
|
+
result.codeNarcBaseDir = path.resolve(codeNarcBaseDir);
|
|
57
64
|
result.codenarcArgs.push(`-basedir=${result.codeNarcBaseDir}`);
|
|
58
65
|
|
|
59
66
|
// Create ruleSet groovy file if necessary
|
|
60
67
|
options.rulesets = await buildRuleSets(options);
|
|
61
68
|
|
|
62
|
-
// Build ruleSet & file CodeNarc arguments
|
|
63
|
-
let defaultFilesPattern = "**/*.groovy,**/*.gvy,**/Jenkinsfile,**/*.gradle,**/*.nf";
|
|
64
|
-
|
|
65
69
|
// RuleSets codeNarc args
|
|
66
70
|
if (options.rulesets && options.rulesets.startsWith("{")) {
|
|
67
71
|
// JSON format
|
|
@@ -72,32 +76,77 @@ async function prepareCodeNarcCall(options) {
|
|
|
72
76
|
result.codenarcArgs.push(`-rulesetfiles=${rulesetFileArgs}`);
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
// Default file patterns
|
|
80
|
+
let filePatterns = defaultFilesPattern.map(filePattern => `**/${filePattern}`).join(",");
|
|
81
|
+
|
|
82
|
+
// Build codenarc arguments from eslint-like formatted positional arguments
|
|
83
|
+
if (positionalArgs.length > 0) {
|
|
84
|
+
if (options.ext && options.ext.length > 0) {
|
|
85
|
+
filePatterns = `/**/*.{` + options.extensions.map(ext => ext.replace(/^\./u, "")) + "}";
|
|
86
|
+
}
|
|
87
|
+
const fileList = [];
|
|
88
|
+
const patternsFinal = positionalArgs
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.map(pathname => {
|
|
91
|
+
let finalPattern = path.normalize(pathname).replace(/\\/gu, "/");
|
|
92
|
+
// Directory: convert into ant pattern
|
|
93
|
+
const resolvedPath = path.resolve(cnPath, pathname);
|
|
94
|
+
if (directoryExists(resolvedPath)) {
|
|
95
|
+
finalPattern = "**/" + path.normalize(pathname.replace(/[/\\]$/u, "")).replace(/\\/gu, "/") + filePatterns;
|
|
96
|
+
}
|
|
97
|
+
// Relative with codeNarcBaseDir
|
|
98
|
+
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) {
|
|
99
|
+
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
100
|
+
fileList.push(absolutePath);
|
|
101
|
+
const relativePath = finalPattern.replace(/\\/gu, "/");
|
|
102
|
+
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
103
|
+
}
|
|
104
|
+
// Absolute or cwd - relative path file
|
|
105
|
+
else if (fs.existsSync(finalPattern)) {
|
|
106
|
+
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
107
|
+
fileList.push(absolutePath);
|
|
108
|
+
const relativePath = path.relative(result.codeNarcBaseDir, path.resolve(finalPattern)).replace(/\\/gu, "/");
|
|
109
|
+
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
110
|
+
}
|
|
111
|
+
// Directory or ant pattern
|
|
112
|
+
return finalPattern;
|
|
113
|
+
})
|
|
114
|
+
.join(",");
|
|
115
|
+
result.codenarcArgs.push(`-includes="${patternsFinal}"`);
|
|
116
|
+
result.codeNarcIncludes = patternsFinal;
|
|
117
|
+
result.inputFileList = fileList;
|
|
118
|
+
}
|
|
75
119
|
// Matching files pattern(s)
|
|
76
|
-
if (cnFiles) {
|
|
120
|
+
else if (cnFiles) {
|
|
77
121
|
const normalizedCnFiles = cnFiles.replace(/^"(.*)"$/, "$1");
|
|
78
|
-
result.codenarcArgs.push(`-includes
|
|
122
|
+
result.codenarcArgs.push(`-includes="${normalizedCnFiles}"`);
|
|
79
123
|
result.codeNarcIncludes = normalizedCnFiles;
|
|
80
124
|
} else {
|
|
81
125
|
// If files not sent, use defaultFilesPattern, guessed from options.rulesets value
|
|
82
|
-
result.codenarcArgs.push(`-includes
|
|
83
|
-
result.codeNarcIncludes =
|
|
126
|
+
result.codenarcArgs.push(`-includes="${filePatterns}"`);
|
|
127
|
+
result.codeNarcIncludes = filePatterns;
|
|
84
128
|
}
|
|
85
129
|
|
|
86
130
|
// Ignore pattern
|
|
87
131
|
if (options.ignorepattern) {
|
|
88
|
-
result.codenarcArgs.push(`-excludes
|
|
132
|
+
result.codenarcArgs.push(`-excludes="${options.ignorepattern}"`);
|
|
89
133
|
result.codeNarcExcludes = options.ignorepattern;
|
|
90
134
|
}
|
|
91
135
|
|
|
92
136
|
// Output
|
|
93
137
|
result.output = options.output.replace(/^"(.*)"$/, "$1");
|
|
94
|
-
if (
|
|
138
|
+
if (
|
|
139
|
+
["txt", "json", "sarif", "none"].includes(result.output) ||
|
|
95
140
|
result.output.endsWith(".txt") ||
|
|
96
141
|
result.output.endsWith(".sarif") ||
|
|
97
|
-
result.output.endsWith(".json")
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
142
|
+
result.output.endsWith(".json")
|
|
143
|
+
) {
|
|
144
|
+
result.outputType = result.output.endsWith(".txt")
|
|
145
|
+
? "txt"
|
|
146
|
+
: result.output.endsWith(".json")
|
|
147
|
+
? "json"
|
|
148
|
+
: result.output.endsWith(".sarif")
|
|
149
|
+
? "sarif"
|
|
101
150
|
: result.output;
|
|
102
151
|
result.codenarcArgs.push(`-report=json:stdout`);
|
|
103
152
|
} else if (["html", "xml"].includes(result.output.split(".").pop())) {
|
|
@@ -130,6 +179,25 @@ async function prepareCodeNarcCall(options) {
|
|
|
130
179
|
return result;
|
|
131
180
|
}
|
|
132
181
|
|
|
182
|
+
// Calculate longest base dir by analyzing the list of files
|
|
183
|
+
async function getCodeNarcBaseDirFromFiles(positionalArgs) {
|
|
184
|
+
// All arguments are not files
|
|
185
|
+
if (!positionalArgs.every(fileOrDirOrPattern => fs.existsSync(fileOrDirOrPattern) || directoryExists(fileOrDirOrPattern))) {
|
|
186
|
+
return process.cwd()
|
|
187
|
+
}
|
|
188
|
+
const folders = positionalArgs.map((fileOrDir) => {
|
|
189
|
+
// Dir
|
|
190
|
+
if (directoryExists(fileOrDir)) {
|
|
191
|
+
return path.resolve(fileOrDir);
|
|
192
|
+
}
|
|
193
|
+
// File dir
|
|
194
|
+
const fileAbsolute = path.resolve(fileOrDir);
|
|
195
|
+
return path.dirname(fileAbsolute);
|
|
196
|
+
});
|
|
197
|
+
const baseDirFromFiles = commondir(folders);
|
|
198
|
+
return baseDirFromFiles
|
|
199
|
+
}
|
|
200
|
+
|
|
133
201
|
// Parse XML result file as js object
|
|
134
202
|
async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult, tmpGroovyFileName, parseErrors) {
|
|
135
203
|
if (!codeNarcJsonResult || !codeNarcJsonResult.codeNarc || !codeNarcJsonResult.packages) {
|
|
@@ -253,7 +321,7 @@ async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult,
|
|
|
253
321
|
const evaluatedVars = evaluateVariables(errRule.variables, errItem.msg, { verbose: options.verbose });
|
|
254
322
|
const errLine = allLines[errItem.line - 1];
|
|
255
323
|
const range = evaluateRange(errItem, errRule, evaluatedVars, errLine, allLines, { verbose: options.verbose });
|
|
256
|
-
if (range) {
|
|
324
|
+
if (range && range.start.character > -1) {
|
|
257
325
|
errItem.range = range;
|
|
258
326
|
}
|
|
259
327
|
}
|
|
@@ -347,6 +415,10 @@ async function buildRuleSets(options) {
|
|
|
347
415
|
? ruleOptions
|
|
348
416
|
: ruleFromConfig;
|
|
349
417
|
const ruleDef = buildCodeNarcRule(ruleName, mergedRuleConfig);
|
|
418
|
+
// If rule has been sent as argument, enable it by default
|
|
419
|
+
if (ruleDef.enabled === false) {
|
|
420
|
+
ruleDef.enabled = true;
|
|
421
|
+
}
|
|
350
422
|
return ruleDef;
|
|
351
423
|
});
|
|
352
424
|
}
|
|
@@ -385,6 +457,10 @@ async function buildRuleSets(options) {
|
|
|
385
457
|
delete rule.ruleName;
|
|
386
458
|
ruleSetJson[ruleName] = rule;
|
|
387
459
|
}
|
|
460
|
+
// Remove UnnecessarySubstring as it is no longer in CodeNarc v3
|
|
461
|
+
if (ruleSetJson["UnnecessarySubstring"] != null) {
|
|
462
|
+
delete ruleSetJson["UnnecessarySubstring"];
|
|
463
|
+
}
|
|
388
464
|
return JSON.stringify(ruleSetJson);
|
|
389
465
|
}
|
|
390
466
|
|
|
@@ -428,4 +504,15 @@ async function manageDeleteTmpFiles(tmpGroovyFileName) {
|
|
|
428
504
|
}
|
|
429
505
|
}
|
|
430
506
|
|
|
507
|
+
function directoryExists(resolvedPath) {
|
|
508
|
+
try {
|
|
509
|
+
return fs.statSync(resolvedPath).isDirectory();
|
|
510
|
+
} catch (error) {
|
|
511
|
+
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
431
518
|
module.exports = { prepareCodeNarcCall, parseCodeNarcResult, manageDeleteTmpFiles };
|