npm-groovy-lint 14.6.0 → 14.6.1-beta202408252305.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/README.md +13 -0
- package/lib/codenarc-caller.js +54 -53
- package/lib/codenarc-factory.js +41 -50
- package/lib/config.js +22 -19
- package/lib/filter.js +8 -15
- package/lib/groovy-lint-fix.js +32 -34
- package/lib/groovy-lint-rules.js +12 -12
- package/lib/groovy-lint.js +40 -41
- package/lib/index.js +3 -3
- package/lib/java/{CodeNarc-3.4.0-alpha+3346775f.jar → CodeNarc-3.5.0.jar} +0 -0
- package/lib/java/CodeNarcServer.jar +0 -0
- package/lib/options.js +45 -54
- package/lib/output.js +23 -23
- package/lib/rules/AssignmentInConditional.js +7 -7
- package/lib/rules/BlankLineBeforePackage.js +11 -11
- package/lib/rules/BlockEndsWithBlankLine.js +6 -6
- package/lib/rules/BlockStartsWithBlankLine.js +6 -6
- package/lib/rules/BracesForClass.js +8 -8
- package/lib/rules/BracesForForLoop.js +9 -9
- package/lib/rules/BracesForIfElse.js +9 -9
- package/lib/rules/BracesForMethod.js +11 -11
- package/lib/rules/BracesForTryCatchFinally.js +7 -7
- package/lib/rules/CatchException.js +4 -4
- package/lib/rules/ClassEndsWithBlankLine.js +6 -6
- package/lib/rules/ClassStartsWithBlankLine.js +6 -6
- package/lib/rules/ClosingBraceNotAlone.js +8 -8
- package/lib/rules/ConsecutiveBlankLines.js +7 -7
- package/lib/rules/DuplicateImport.js +6 -6
- package/lib/rules/DuplicateNumberLiteral.js +6 -6
- package/lib/rules/DuplicateStringLiteral.js +6 -6
- package/lib/rules/ElseBlockBraces.js +10 -10
- package/lib/rules/ExplicitArrayListInstantiation.js +7 -7
- package/lib/rules/ExplicitLinkedListInstantiation.js +7 -7
- package/lib/rules/FileEndsWithoutNewline.js +7 -7
- package/lib/rules/GStringExpressionWithinString.js +7 -7
- package/lib/rules/IfStatementBraces.js +10 -10
- package/lib/rules/Indentation.js +14 -14
- package/lib/rules/IndentationClosingBraces.js +8 -8
- package/lib/rules/IndentationComments.js +6 -6
- package/lib/rules/InsecureRandom.js +14 -14
- package/lib/rules/JavaIoPackageAccess.js +6 -6
- package/lib/rules/MethodCount.js +6 -6
- package/lib/rules/MethodParameterTypeRequired.js +6 -6
- package/lib/rules/MethodReturnTypeRequired.js +6 -6
- package/lib/rules/MisorderedStaticImports.js +14 -14
- package/lib/rules/MissingBlankLineAfterImports.js +6 -6
- package/lib/rules/MissingBlankLineAfterPackage.js +6 -6
- package/lib/rules/NoDef.js +4 -4
- package/lib/rules/NoJavaUtilDate.js +4 -4
- package/lib/rules/NoTabCharacter.js +7 -7
- package/lib/rules/SimpleDateFormatMissingLocale.js +4 -4
- package/lib/rules/SpaceAfterCatch.js +7 -7
- package/lib/rules/SpaceAfterComma.js +9 -9
- package/lib/rules/SpaceAfterFor.js +8 -8
- package/lib/rules/SpaceAfterIf.js +10 -10
- package/lib/rules/SpaceAfterMethodCallName.js +7 -7
- package/lib/rules/SpaceAfterOpeningBrace.js +9 -9
- package/lib/rules/SpaceAfterSemicolon.js +8 -8
- package/lib/rules/SpaceAfterSwitch.js +8 -8
- package/lib/rules/SpaceAfterWhile.js +7 -7
- package/lib/rules/SpaceAroundOperator.js +14 -14
- package/lib/rules/SpaceBeforeClosingBrace.js +8 -8
- package/lib/rules/SpaceBeforeOpeningBrace.js +9 -9
- package/lib/rules/SpaceInsideParentheses.js +17 -17
- package/lib/rules/SystemExit.js +4 -4
- package/lib/rules/TrailingWhitespace.js +8 -8
- package/lib/rules/UnnecessaryDefInFieldDeclaration.js +8 -8
- package/lib/rules/UnnecessaryDefInMethodDeclaration.js +7 -7
- package/lib/rules/UnnecessaryDefInVariableDeclaration.js +9 -9
- package/lib/rules/UnnecessaryDotClass.js +7 -7
- package/lib/rules/UnnecessaryFinalOnPrivateMethod.js +7 -7
- package/lib/rules/UnnecessaryGString.js +14 -14
- package/lib/rules/UnnecessaryGroovyImport.js +6 -6
- package/lib/rules/UnnecessaryPackageReference.js +9 -9
- package/lib/rules/UnnecessaryParenthesesForMethodCallWithClosure.js +9 -9
- package/lib/rules/UnnecessaryPublicModifier.js +4 -4
- package/lib/rules/UnnecessarySemicolon.js +10 -13
- package/lib/rules/UnnecessaryToString.js +8 -8
- package/lib/rules/UnusedImport.js +10 -10
- package/lib/rules/UnusedMethodParameter.js +6 -6
- package/lib/rules/UnusedVariable.js +6 -6
- package/lib/rules/VariableName.js +11 -11
- package/lib/rules/VariableTypeRequired.js +11 -11
- package/lib/utils.js +62 -43
- package/package.json +22 -19
package/lib/options.js
CHANGED
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
* @author Nicolas Vuillamy
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
6
|
//------------------------------------------------------------------------------
|
|
9
7
|
// Requirements
|
|
10
8
|
//------------------------------------------------------------------------------
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
import optionator from "optionator";
|
|
13
11
|
|
|
14
12
|
const defaultServerPort = process.env.SERVER_PORT ? process.env.SERVER_PORT : "7484";
|
|
15
13
|
|
|
@@ -17,36 +15,36 @@ const defaultServerPort = process.env.SERVER_PORT ? process.env.SERVER_PORT : "7
|
|
|
17
15
|
// Initialization and Public Interface
|
|
18
16
|
//------------------------------------------------------------------------------
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
export const optionsDefinition = optionator({
|
|
21
19
|
prepend: "npm-groovy-lint [options]",
|
|
22
20
|
defaults: {
|
|
23
21
|
concatRepeatedArrays: true,
|
|
24
|
-
mergeRepeatedObjects: true
|
|
22
|
+
mergeRepeatedObjects: true,
|
|
25
23
|
},
|
|
26
24
|
options: [
|
|
27
25
|
{
|
|
28
26
|
option: "ext",
|
|
29
27
|
type: "[String]",
|
|
30
|
-
description: "Specify Groovy file extensions"
|
|
28
|
+
description: "Specify Groovy file extensions",
|
|
31
29
|
},
|
|
32
30
|
{
|
|
33
31
|
option: "source",
|
|
34
32
|
alias: "s",
|
|
35
33
|
type: "String",
|
|
36
34
|
description: "Source text to lint (if no path/files arguments)",
|
|
37
|
-
example: ["import groovyx.net.http.HTTPBuilder\n\nimport class Toto { \n }"]
|
|
35
|
+
example: ["import groovyx.net.http.HTTPBuilder\n\nimport class Toto { \n }"],
|
|
38
36
|
},
|
|
39
37
|
{
|
|
40
38
|
option: "sourcefilepath",
|
|
41
39
|
type: "String",
|
|
42
40
|
dependsOn: ["source"],
|
|
43
41
|
description: "Full path of the file whose content is sent in source argument ",
|
|
44
|
-
example: ["C:/some/folder/myScript.groovy", "/var/some/folder/myScript.groovy"]
|
|
42
|
+
example: ["C:/some/folder/myScript.groovy", "/var/some/folder/myScript.groovy"],
|
|
45
43
|
},
|
|
46
44
|
{
|
|
47
45
|
option: "parse",
|
|
48
46
|
type: "Boolean",
|
|
49
|
-
description: "Try to parse the source code with GroovyShell and return errors (use argument --no-parse if you want to deactivate)"
|
|
47
|
+
description: "Try to parse the source code with GroovyShell and return errors (use argument --no-parse if you want to deactivate)",
|
|
50
48
|
},
|
|
51
49
|
{
|
|
52
50
|
option: "config",
|
|
@@ -55,17 +53,17 @@ let options = optionator({
|
|
|
55
53
|
default: process.cwd(),
|
|
56
54
|
description:
|
|
57
55
|
"Custom path to directory containing GroovyLint config file.\n Default: Found groovylintrc.js/json/yml/package.json config file, or default npm-groovy-lint config if not defined. \nNote: command-line arguments have priority on config file properties",
|
|
58
|
-
example: ["./config", "./config/whatever"]
|
|
56
|
+
example: ["./config", "./config/whatever"],
|
|
59
57
|
},
|
|
60
58
|
{
|
|
61
59
|
option: "format",
|
|
62
60
|
type: "Boolean",
|
|
63
|
-
description: "Format source code"
|
|
61
|
+
description: "Format source code",
|
|
64
62
|
},
|
|
65
63
|
{
|
|
66
64
|
option: "fix",
|
|
67
65
|
type: "Boolean",
|
|
68
|
-
description: "Automatically fix problems when possible"
|
|
66
|
+
description: "Automatically fix problems when possible",
|
|
69
67
|
},
|
|
70
68
|
{
|
|
71
69
|
option: "fixrules",
|
|
@@ -74,14 +72,14 @@ let options = optionator({
|
|
|
74
72
|
default: "all",
|
|
75
73
|
dependsOn: ["fix"],
|
|
76
74
|
description: "Option for --fix argument: List of rule identifiers to fix (if not specified, all available fixes will be applied)",
|
|
77
|
-
example: ["SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"]
|
|
75
|
+
example: ["SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"],
|
|
78
76
|
},
|
|
79
77
|
{
|
|
80
78
|
option: "ignorepattern",
|
|
81
79
|
alias: "i",
|
|
82
80
|
type: "String",
|
|
83
81
|
description: "Comma-separated list of Ant-style file patterns specifying files that must be ignored. Default: none",
|
|
84
|
-
example: ["**/test/*"]
|
|
82
|
+
example: ["**/test/*"],
|
|
85
83
|
},
|
|
86
84
|
{
|
|
87
85
|
option: "rulesets",
|
|
@@ -92,8 +90,8 @@ let options = optionator({
|
|
|
92
90
|
example: [
|
|
93
91
|
"./config/codenarc/RuleSet-Custom.groovy",
|
|
94
92
|
"./path/to/my/ruleset/files",
|
|
95
|
-
'Indentation{"spacesPerIndentLevel":2,"severity":"warning"},UnnecessarySemicolon,UnnecessaryGString,ConsecutiveBlankLines{"severity":"warning"},NoTabCharacter'
|
|
96
|
-
]
|
|
93
|
+
'Indentation{"spacesPerIndentLevel":2,"severity":"warning"},UnnecessarySemicolon,UnnecessaryGString,ConsecutiveBlankLines{"severity":"warning"},NoTabCharacter',
|
|
94
|
+
],
|
|
97
95
|
},
|
|
98
96
|
{
|
|
99
97
|
option: "rulesetsoverridetype",
|
|
@@ -103,7 +101,7 @@ let options = optionator({
|
|
|
103
101
|
default: "replaceConfig",
|
|
104
102
|
description:
|
|
105
103
|
"If list of rules sent in rulesets option, defines if they replace rules defined in .groovylintrc.json, or if they are appended",
|
|
106
|
-
example: ["replaceConfig", "appendConfig"]
|
|
104
|
+
example: ["replaceConfig", "appendConfig"],
|
|
107
105
|
},
|
|
108
106
|
{
|
|
109
107
|
option: "output",
|
|
@@ -119,8 +117,8 @@ let options = optionator({
|
|
|
119
117
|
"./logs/myLintResults.json",
|
|
120
118
|
"./logs/myLintResults.sarif",
|
|
121
119
|
"./logs/myLintResults.html",
|
|
122
|
-
"./logs/myLintResults.xml"
|
|
123
|
-
]
|
|
120
|
+
"./logs/myLintResults.xml",
|
|
121
|
+
],
|
|
124
122
|
},
|
|
125
123
|
{
|
|
126
124
|
option: "loglevel",
|
|
@@ -129,12 +127,12 @@ let options = optionator({
|
|
|
129
127
|
enum: ["error", "warning", "info"],
|
|
130
128
|
default: "info",
|
|
131
129
|
description: "Log level (error,warning,info)",
|
|
132
|
-
example: ["warning", "error"]
|
|
130
|
+
example: ["warning", "error"],
|
|
133
131
|
},
|
|
134
132
|
{
|
|
135
133
|
option: "verbose",
|
|
136
134
|
type: "Boolean",
|
|
137
|
-
description: "More outputs in console, including performed fixes"
|
|
135
|
+
description: "More outputs in console, including performed fixes",
|
|
138
136
|
},
|
|
139
137
|
{
|
|
140
138
|
option: "failon",
|
|
@@ -143,22 +141,22 @@ let options = optionator({
|
|
|
143
141
|
default: "info",
|
|
144
142
|
description:
|
|
145
143
|
"Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Every failure level includes the more critical ones.",
|
|
146
|
-
example: ["error", "warning", "info", "none"]
|
|
144
|
+
example: ["error", "warning", "info", "none"],
|
|
147
145
|
},
|
|
148
146
|
{
|
|
149
147
|
option: "failonerror",
|
|
150
148
|
type: "Boolean",
|
|
151
|
-
description: "(Deprecated) Fails if at least one error is found"
|
|
149
|
+
description: "(Deprecated) Fails if at least one error is found",
|
|
152
150
|
},
|
|
153
151
|
{
|
|
154
152
|
option: "failonwarning",
|
|
155
153
|
type: "Boolean",
|
|
156
|
-
description: "(Deprecated) Fails if at least one warning is found"
|
|
154
|
+
description: "(Deprecated) Fails if at least one warning is found",
|
|
157
155
|
},
|
|
158
156
|
{
|
|
159
157
|
option: "failoninfo",
|
|
160
158
|
type: "Boolean",
|
|
161
|
-
description: "(Deprecated) Fails if at least one error is found"
|
|
159
|
+
description: "(Deprecated) Fails if at least one error is found",
|
|
162
160
|
},
|
|
163
161
|
{
|
|
164
162
|
option: "codenarcargs",
|
|
@@ -166,27 +164,27 @@ let options = optionator({
|
|
|
166
164
|
description:
|
|
167
165
|
"Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored). Doc: http://codenarc.github.io/CodeNarc/codenarc-command-line.html",
|
|
168
166
|
example: [
|
|
169
|
-
'npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml'
|
|
170
|
-
]
|
|
167
|
+
'npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml',
|
|
168
|
+
],
|
|
171
169
|
},
|
|
172
170
|
{
|
|
173
171
|
option: "noserver",
|
|
174
172
|
type: "Boolean",
|
|
175
173
|
description:
|
|
176
|
-
"For better performances, npm-groovy-lint runs a local server to eep CodeNarc alive instead of loading java/groovy at each call. If you don't want that, send this argument"
|
|
174
|
+
"For better performances, npm-groovy-lint runs a local server to eep CodeNarc alive instead of loading java/groovy at each call. If you don't want that, send this argument",
|
|
177
175
|
},
|
|
178
176
|
{
|
|
179
177
|
option: "serverhost",
|
|
180
178
|
type: "String",
|
|
181
179
|
default: "http://localhost",
|
|
182
|
-
description: "If use of CodeNarc server, host where is the CodeNarc server (default: localhost)"
|
|
180
|
+
description: "If use of CodeNarc server, host where is the CodeNarc server (default: localhost)",
|
|
183
181
|
},
|
|
184
182
|
{
|
|
185
183
|
option: "serverport",
|
|
186
184
|
type: "String",
|
|
187
185
|
default: defaultServerPort,
|
|
188
186
|
description: `If use of CodeNarc server, port of the CodeNarc server (default: ${defaultServerPort})`,
|
|
189
|
-
example: ["2702"]
|
|
187
|
+
example: ["2702"],
|
|
190
188
|
},
|
|
191
189
|
{
|
|
192
190
|
option: "javaexecutable",
|
|
@@ -194,48 +192,48 @@ let options = optionator({
|
|
|
194
192
|
type: "String",
|
|
195
193
|
default: "java",
|
|
196
194
|
description: "If you do not want to use default java executable to run CodeNarcServer, you can override it",
|
|
197
|
-
example: [`C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java.exe`, `/users/nvuillam/jdk1.8.0_144/bin/java`]
|
|
195
|
+
example: [`C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java.exe`, `/users/nvuillam/jdk1.8.0_144/bin/java`],
|
|
198
196
|
},
|
|
199
197
|
{
|
|
200
198
|
option: "javaoptions",
|
|
201
199
|
type: "String",
|
|
202
200
|
default: "-Xms256m,-Xmx2048m",
|
|
203
201
|
description: "Override java options",
|
|
204
|
-
example: [`-Xms256m,-Xmx2048m`]
|
|
202
|
+
example: [`-Xms256m,-Xmx2048m`],
|
|
205
203
|
},
|
|
206
204
|
{
|
|
207
205
|
option: "killserver",
|
|
208
206
|
type: "Boolean",
|
|
209
|
-
description: "Terminate the CodeNarcServer if running"
|
|
207
|
+
description: "Terminate the CodeNarcServer if running",
|
|
210
208
|
},
|
|
211
209
|
{
|
|
212
210
|
option: "nolintafter",
|
|
213
211
|
type: "Boolean",
|
|
214
|
-
description: "Do not lint again after format and fix options (useful for client calling Npm Groovy Lint)"
|
|
212
|
+
description: "Do not lint again after format and fix options (useful for client calling Npm Groovy Lint)",
|
|
215
213
|
},
|
|
216
214
|
{
|
|
217
215
|
option: "returnrules",
|
|
218
216
|
type: "Boolean",
|
|
219
|
-
description: "Return rule descriptions and url if this argument is set"
|
|
217
|
+
description: "Return rule descriptions and url if this argument is set",
|
|
220
218
|
},
|
|
221
219
|
{
|
|
222
220
|
option: "insight",
|
|
223
221
|
type: "Boolean",
|
|
224
222
|
default: false,
|
|
225
223
|
description:
|
|
226
|
-
"npm-groovy-lint collects anonymous usage statistics using package https://www.npmjs.com/package/insight. If you want to enable them, use --insight option"
|
|
224
|
+
"npm-groovy-lint collects anonymous usage statistics using package https://www.npmjs.com/package/insight. If you want to enable them, use --insight option",
|
|
227
225
|
},
|
|
228
226
|
{
|
|
229
227
|
option: "help",
|
|
230
228
|
alias: "h",
|
|
231
229
|
type: "Boolean",
|
|
232
|
-
description: "Show help (npm-groovy-lint -help OPTIONNAME to see option detail)"
|
|
230
|
+
description: "Show help (npm-groovy-lint -help OPTIONNAME to see option detail)",
|
|
233
231
|
},
|
|
234
232
|
{
|
|
235
233
|
option: "version",
|
|
236
234
|
alias: "v",
|
|
237
235
|
type: "Boolean",
|
|
238
|
-
description: "Show version"
|
|
236
|
+
description: "Show version",
|
|
239
237
|
},
|
|
240
238
|
{
|
|
241
239
|
option: "path",
|
|
@@ -243,15 +241,15 @@ let options = optionator({
|
|
|
243
241
|
type: "path::String",
|
|
244
242
|
default: ".",
|
|
245
243
|
description: "(DEPRECATED) Directory containing the files to lint (default: current directory)",
|
|
246
|
-
example: ["./path/to/my/groovy/files"]
|
|
244
|
+
example: ["./path/to/my/groovy/files"],
|
|
247
245
|
},
|
|
248
246
|
{
|
|
249
247
|
option: "files",
|
|
250
248
|
alias: "f",
|
|
251
249
|
type: "String",
|
|
252
250
|
description: "(DEPRECATED) Comma-separated list of Ant-style file patterns specifying files that must be included",
|
|
253
|
-
example: ["**/Jenkinsfile", "**/*.groovy", "**/*.gradle"]
|
|
254
|
-
}
|
|
251
|
+
example: ["**/Jenkinsfile", "**/*.groovy", "**/*.gradle"],
|
|
252
|
+
},
|
|
255
253
|
],
|
|
256
254
|
mutuallyExclusive: [
|
|
257
255
|
["files", "source", "codenarcargs", "help", "version"],
|
|
@@ -274,23 +272,16 @@ let options = optionator({
|
|
|
274
272
|
"nolintafter",
|
|
275
273
|
"noserver",
|
|
276
274
|
"serverhost",
|
|
277
|
-
"serverport"
|
|
278
|
-
]
|
|
275
|
+
"serverport",
|
|
276
|
+
],
|
|
279
277
|
],
|
|
280
278
|
["noserver", ["serverhost", "serverport", "killserver"]],
|
|
281
279
|
["fix", "format"],
|
|
282
280
|
[
|
|
283
281
|
["fix", "format"],
|
|
284
|
-
["failonerror", "failonwarning", "failoninfo"]
|
|
285
|
-
]
|
|
286
|
-
]
|
|
282
|
+
["failonerror", "failonwarning", "failoninfo"],
|
|
283
|
+
],
|
|
284
|
+
],
|
|
287
285
|
});
|
|
288
286
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
// Export:
|
|
292
|
-
// - parse(args)
|
|
293
|
-
// - generateHelp()
|
|
294
|
-
// - generateHelpForOption(optionName)
|
|
295
|
-
// - defaultServerPort
|
|
296
|
-
module.exports = options;
|
|
287
|
+
optionsDefinition.defaultServerPort = defaultServerPort;
|
package/lib/output.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Output management
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import ansiColors from "ansi-colors";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { SarifBuilder, SarifRunBuilder, SarifResultBuilder, SarifRuleBuilder } from "node-sarif-builder";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { isErrorInLogLevelScope, getNpmGroovyLintVersion } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
// Compute statistics for output
|
|
9
9
|
function computeStats(lintResult) {
|
|
@@ -23,7 +23,7 @@ function computeStats(lintResult) {
|
|
|
23
23
|
totalRemainingInfoNumber: 0,
|
|
24
24
|
|
|
25
25
|
detectedRules: {},
|
|
26
|
-
fixedRules: {}
|
|
26
|
+
fixedRules: {},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// No files = no result (mostly happens when lint has been cancelled before being completed)
|
|
@@ -56,11 +56,11 @@ function computeStats(lintResult) {
|
|
|
56
56
|
// Collect stats about errors in a linted / formatted / fixed file
|
|
57
57
|
function appendErrorTypeStats(severity, fileErrors, counterResultsSummary) {
|
|
58
58
|
// Found
|
|
59
|
-
const fileFoundSeverityNumber = fileErrors.filter(err => {
|
|
59
|
+
const fileFoundSeverityNumber = fileErrors.filter((err) => {
|
|
60
60
|
return err.severity === severity;
|
|
61
61
|
}).length;
|
|
62
62
|
// Fixed
|
|
63
|
-
const fileFixedSeverityNumber = fileErrors.filter(err => {
|
|
63
|
+
const fileFixedSeverityNumber = fileErrors.filter((err) => {
|
|
64
64
|
return err.severity === severity && err.fixed && err.fixed === true;
|
|
65
65
|
}).length;
|
|
66
66
|
// Remaining
|
|
@@ -91,7 +91,7 @@ function appendErrorTypeStats(severity, fileErrors, counterResultsSummary) {
|
|
|
91
91
|
return {
|
|
92
92
|
found: fileFoundSeverityNumber,
|
|
93
93
|
fixed: fileFixedSeverityNumber,
|
|
94
|
-
remaining: fileRemainingSeverityNumber
|
|
94
|
+
remaining: fileRemainingSeverityNumber,
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -103,12 +103,12 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
103
103
|
// Disable colors if output results in text file or no output result
|
|
104
104
|
if (output.includes(".txt") || output === "none") {
|
|
105
105
|
// Disable ansi colors if output in txt file
|
|
106
|
-
|
|
106
|
+
ansiColors.enabled = false;
|
|
107
107
|
}
|
|
108
108
|
// Errors
|
|
109
109
|
for (const fileNm of Object.keys(lintResult.files)) {
|
|
110
110
|
const fileErrors = lintResult.files[fileNm].errors;
|
|
111
|
-
let fileOutputString =
|
|
111
|
+
let fileOutputString = ansiColors.underline(fileNm) + "\n";
|
|
112
112
|
let showFileInOutput = false;
|
|
113
113
|
for (const err of fileErrors) {
|
|
114
114
|
if (!isErrorInLogLevelScope(err.severity, options.loglevel)) {
|
|
@@ -141,7 +141,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
141
141
|
" " +
|
|
142
142
|
err.line.toString().padEnd(4, " ") +
|
|
143
143
|
" " +
|
|
144
|
-
|
|
144
|
+
ansiColors[color](err.severity.padEnd(7, " ")) +
|
|
145
145
|
" " +
|
|
146
146
|
err.msg +
|
|
147
147
|
" " +
|
|
@@ -153,26 +153,26 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
153
153
|
outputString += fileOutputString;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
outputString += "\nnpm-groovy-lint results in " +
|
|
156
|
+
outputString += "\nnpm-groovy-lint results in " + ansiColors.bold(lintResult.summary.totalFilesLinted) + " linted files:";
|
|
157
157
|
|
|
158
158
|
// Summary table
|
|
159
159
|
const errorTableLine = {
|
|
160
160
|
Severity: "Error",
|
|
161
161
|
"Total found": lintResult.summary.totalFoundErrorNumber,
|
|
162
162
|
"Total fixed": lintResult.summary.totalFixedErrorNumber,
|
|
163
|
-
"Total remaining": lintResult.summary.totalRemainingErrorNumber
|
|
163
|
+
"Total remaining": lintResult.summary.totalRemainingErrorNumber,
|
|
164
164
|
};
|
|
165
165
|
const warningTableLine = {
|
|
166
166
|
Severity: "Warning",
|
|
167
167
|
"Total found": lintResult.summary.totalFoundWarningNumber,
|
|
168
168
|
"Total fixed": lintResult.summary.totalFixedWarningNumber,
|
|
169
|
-
"Total remaining": lintResult.summary.totalRemainingWarningNumber
|
|
169
|
+
"Total remaining": lintResult.summary.totalRemainingWarningNumber,
|
|
170
170
|
};
|
|
171
171
|
const infoTableLine = {
|
|
172
172
|
Severity: "Info",
|
|
173
173
|
"Total found": lintResult.summary.totalFoundInfoNumber,
|
|
174
174
|
"Total fixed": lintResult.summary.totalFixedInfoNumber,
|
|
175
|
-
"Total remaining": lintResult.summary.totalRemainingInfoNumber
|
|
175
|
+
"Total remaining": lintResult.summary.totalRemainingInfoNumber,
|
|
176
176
|
};
|
|
177
177
|
const summaryTable = [];
|
|
178
178
|
if (isErrorInLogLevelScope("error", options.loglevel)) {
|
|
@@ -188,7 +188,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
188
188
|
// Output text log in file
|
|
189
189
|
if (output.endsWith(".txt")) {
|
|
190
190
|
const fullFileContent = outputString;
|
|
191
|
-
|
|
191
|
+
fs.writeFileSync(output, fullFileContent);
|
|
192
192
|
console.table(summaryTable, fixer ? ["Severity", "Total found", "Total fixed", "Total remaining"] : ["Severity", "Total found"]);
|
|
193
193
|
const absolutePath = path.resolve(".", output);
|
|
194
194
|
console.info("GroovyLint: Logged results in file " + absolutePath);
|
|
@@ -203,7 +203,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
203
203
|
// Output log
|
|
204
204
|
if (output.endsWith(".json")) {
|
|
205
205
|
const fullFileContent = JSON.stringify(lintResult, null, 2);
|
|
206
|
-
|
|
206
|
+
fs.writeFileSync(output, fullFileContent);
|
|
207
207
|
const absolutePath = path.resolve(".", output);
|
|
208
208
|
console.info("GroovyLint: Logged results in file " + absolutePath);
|
|
209
209
|
} else {
|
|
@@ -216,7 +216,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
|
|
|
216
216
|
const sarifJsonString = buildSarifResult(lintResult);
|
|
217
217
|
// SARIF file
|
|
218
218
|
if (output.endsWith(".sarif")) {
|
|
219
|
-
|
|
219
|
+
fs.writeFileSync(output, sarifJsonString);
|
|
220
220
|
const absolutePath = path.resolve(".", output);
|
|
221
221
|
outputString = "GroovyLint: Logged SARIF results in file " + absolutePath;
|
|
222
222
|
console.info(outputString);
|
|
@@ -240,7 +240,7 @@ function buildSarifResult(lintResult) {
|
|
|
240
240
|
const sarifRunBuilder = new SarifRunBuilder().initSimple({
|
|
241
241
|
toolDriverName: "npm-groovy-lint",
|
|
242
242
|
toolDriverVersion: getNpmGroovyLintVersion(),
|
|
243
|
-
url: "https://nvuillam.github.io/npm-groovy-lint/"
|
|
243
|
+
url: "https://nvuillam.github.io/npm-groovy-lint/",
|
|
244
244
|
});
|
|
245
245
|
// SARIF rules
|
|
246
246
|
for (const ruleId of Object.keys(lintResult.rules || {})) {
|
|
@@ -248,7 +248,7 @@ function buildSarifResult(lintResult) {
|
|
|
248
248
|
const sarifRuleBuilder = new SarifRuleBuilder().initSimple({
|
|
249
249
|
ruleId: ruleId,
|
|
250
250
|
shortDescriptionText: rule.description,
|
|
251
|
-
helpUri: rule.docUrl
|
|
251
|
+
helpUri: rule.docUrl,
|
|
252
252
|
});
|
|
253
253
|
sarifRunBuilder.addRule(sarifRuleBuilder);
|
|
254
254
|
}
|
|
@@ -261,7 +261,7 @@ function buildSarifResult(lintResult) {
|
|
|
261
261
|
level: err.severity === "info" ? "note" : err.severity, // Other values can be "warning" or "error"
|
|
262
262
|
messageText: err.msg,
|
|
263
263
|
ruleId: err.rule,
|
|
264
|
-
fileUri: process.env.SARIF_URI_ABSOLUTE ? "file:///" + fileNm.replace(/\\/g, "/") : path.relative(process.cwd(), fileNm)
|
|
264
|
+
fileUri: process.env.SARIF_URI_ABSOLUTE ? "file:///" + fileNm.replace(/\\/g, "/") : path.relative(process.cwd(), fileNm),
|
|
265
265
|
};
|
|
266
266
|
if (err && err.range && err.range.start && (err.range.start.line === 0 || err.range.start.line > 0)) {
|
|
267
267
|
sarifResultInit.startLine = fixLine(err.range.start.line);
|
|
@@ -291,4 +291,4 @@ function fixCol(val) {
|
|
|
291
291
|
return val === 0 ? 1 : val + 1;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
export { computeStats, processOutput };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Assignment in condition
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { getStringRange } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
const rule = {
|
|
6
6
|
range: {
|
|
7
7
|
type: "function",
|
|
8
8
|
func: (errLine, errItem) => {
|
|
9
9
|
return getStringRange(errLine, /(?<!=|!|>|<)=(?!=)/g, errItem);
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
11
|
},
|
|
12
12
|
fix: {
|
|
13
13
|
label: `Replace "=" by "=="`,
|
|
14
14
|
type: "replaceString",
|
|
15
15
|
before: /(?<!=|!|>|<)=(?!=)/g,
|
|
16
|
-
after: "=="
|
|
16
|
+
after: "==",
|
|
17
17
|
},
|
|
18
18
|
tests: [
|
|
19
19
|
{
|
|
@@ -48,9 +48,9 @@ while (value == true && value != false) {
|
|
|
48
48
|
|
|
49
49
|
(value == true) ? x : y
|
|
50
50
|
(value == true) ?: x
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
]
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
export { rule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Blank line before package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { getVariable } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
const rule = {
|
|
6
6
|
scope: "file",
|
|
@@ -16,7 +16,7 @@ const rule = {
|
|
|
16
16
|
allLines.splice(lineNumber + 1, 1);
|
|
17
17
|
}
|
|
18
18
|
return allLines;
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
tests: [
|
|
@@ -43,8 +43,8 @@ class BuildEnv implements Serializable {
|
|
|
43
43
|
private String dockerRegistryCredsId
|
|
44
44
|
private Map envVars
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
}
|
|
46
|
+
`,
|
|
47
|
+
},
|
|
48
48
|
],
|
|
49
49
|
rangeTests: [
|
|
50
50
|
{
|
|
@@ -63,15 +63,15 @@ class BuildEnv implements Serializable {
|
|
|
63
63
|
expectedRange: {
|
|
64
64
|
start: {
|
|
65
65
|
line: 1,
|
|
66
|
-
character: 0
|
|
66
|
+
character: 0,
|
|
67
67
|
},
|
|
68
68
|
end: {
|
|
69
69
|
line: 1,
|
|
70
|
-
character: 21
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]
|
|
70
|
+
character: 21,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
export { rule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Unused import
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { getVariable } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
const rule = {
|
|
6
6
|
scope: "file",
|
|
@@ -14,7 +14,7 @@ const rule = {
|
|
|
14
14
|
allLines.splice(lineNumber, 1);
|
|
15
15
|
}
|
|
16
16
|
return allLines;
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
tests: [
|
|
@@ -38,9 +38,9 @@ if (true) {
|
|
|
38
38
|
if (false) {
|
|
39
39
|
def b = 2
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
]
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
export { rule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Unused import
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { getVariable } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
const rule = {
|
|
6
6
|
scope: "file",
|
|
@@ -14,7 +14,7 @@ const rule = {
|
|
|
14
14
|
allLines.splice(lineNumber, 1);
|
|
15
15
|
}
|
|
16
16
|
return allLines;
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
tests: [
|
|
@@ -38,9 +38,9 @@ if (true) {
|
|
|
38
38
|
if (false) {
|
|
39
39
|
def b = 2
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
]
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
export { rule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Braces for class
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { moveOpeningBracket, findRangeBetweenStrings } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
const rule = {
|
|
6
6
|
scope: "file",
|
|
@@ -9,14 +9,14 @@ const rule = {
|
|
|
9
9
|
type: "function",
|
|
10
10
|
func: (_errLine, errItem, _evaluatedVars, allLines) => {
|
|
11
11
|
return findRangeBetweenStrings(allLines, errItem, "class", "{");
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
13
|
},
|
|
14
14
|
fix: {
|
|
15
15
|
label: "Move opening brace on the same line",
|
|
16
16
|
type: "function",
|
|
17
17
|
func: (allLines, variables) => {
|
|
18
18
|
return moveOpeningBracket(allLines, variables);
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
20
|
},
|
|
21
21
|
tests: [
|
|
22
22
|
{
|
|
@@ -30,7 +30,7 @@ public class lelamanul
|
|
|
30
30
|
public class lelamanul {
|
|
31
31
|
def a = 1
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
`,
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
sourceBefore: `
|
|
@@ -42,9 +42,9 @@ public class lelamanul
|
|
|
42
42
|
public class lelamanul {
|
|
43
43
|
def a = 1
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
]
|
|
45
|
+
`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
export { rule };
|