npm-groovy-lint 16.0.1 → 16.1.2-beta-202601241018.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 CHANGED
@@ -12,7 +12,8 @@
12
12
  [![Docker Pulls](https://img.shields.io/docker/pulls/nvuillam/npm-groovy-lint)](https://hub.docker.com/r/nvuillam/npm-groovy-lint)
13
13
  [![Docker Stars](https://img.shields.io/docker/stars/nvuillam/npm-groovy-lint)](https://hub.docker.com/r/nvuillam/npm-groovy-lint)
14
14
  [![License](https://img.shields.io/npm/l/npm-groovy-lint.svg)](https://github.com/nvuillam/npm-groovy-lint/blob/master/package.json)
15
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
15
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)<!-- gh-dependents-info-used-by-start -->
16
+ [![Generated by github-dependents-info](https://img.shields.io/static/v1?label=Used%20by&message=54&color=informational&logo=slickpic)](https://github.com/nvuillam/npm-groovy-lint/blob/main/docs/github-dependents-info.md)<!-- gh-dependents-info-used-by-end -->
16
17
 
17
18
  ## Groovy & Jenkinsfile Linter, Formatter and Auto-fixer
18
19
 
@@ -53,6 +54,7 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
53
54
  | --format | Boolean | Format source code |
54
55
  | --fix | Boolean | Automatically fix problems when possible<br/> See [Auto-fixable rules](#auto-fixable-rules) |
55
56
  | -x<br/> --fixrules | String | Option for --fix argument: List of rule identifiers to fix (if not specified, all available fixes will be applied). See [Auto-fixable rules](#auto-fixable-rules) <br/> Examples:<br/> - `"SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"`<br/> - `"Indentation"`<br/> |
57
+ | --fixrulesexclude | String | Option for --fix argument: Comma-separated list of rule identifiers to exclude from fixes (if not specified, none are excluded). If used with --fixrules, exclusion is applied last (excluded rules cancel included rules). See [Auto-fixable rules](#auto-fixable-rules) <br/> Examples:<br/> - `"Indentation,IndentationClosingBraces,BracesForIfElse"`<br/> - `"UnnecessarySemicolon,SpaceAfterComma"`<br/> |
56
58
  | --nolintafter | Boolean | When format or fix is called, a new lint is performed after the fixes to update the returned error list. If you just want the updated source code and do not care about the error logs, use this parameter to improve performances |
57
59
  | -r<br/> --rulesets | String | [RuleSet file(s)](http://codenarc.github.io/CodeNarc/codenarc-creating-ruleset.html) to use for linting, if you do not want to use recommended rules or .groovylintrc.js defined rules.<br/>If list of comma separated strings corresponding to CodeNarc rules, a RuleSet file will be dynamically generated </br> Examples:<br/> - `"./config/codenarc/RuleSet-Custom.groovy"`<br/> - `"./path/to/my/ruleset/files"`<br/>- `Indentation{"spacesPerIndentLevel":2,"severity":"warning"},UnnecessarySemicolon,UnnecessaryGString` |
58
60
  | --rulesetsoverridetype | String | If list of rules sent in rulesets option, defines if they replace rules defined in .groovylintrc.json, or if they are appended<br/> Values: `replaceConfig` (default), `appendConfig` |
@@ -114,6 +116,18 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
114
116
  npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy
115
117
  ```
116
118
 
119
+ - Fix files but exclude specific rules (useful for avoiding buggy indentation rules)
120
+
121
+ ```shell
122
+ npm-groovy-lint --fix --fixrulesexclude Indentation,IndentationClosingBraces,BracesForIfElse my/path/to/file.groovy
123
+ ```
124
+
125
+ - Fix only specific rules
126
+
127
+ ```shell
128
+ npm-groovy-lint --fix --fixrules SpaceAfterComma,TrailingWhitespace,UnusedImport my/path/to/file.groovy
129
+ ```
130
+
117
131
  - Get formatted sources in stdout from stdin
118
132
 
119
133
  ```shell
@@ -140,7 +154,7 @@ Any **question**, **problem** or **enhancement request** ? Ask [**here**](https:
140
154
 
141
155
  - If you have issues with v9, install previous version with `npm install -g npm-groovy-lint@8.2.0`
142
156
  - Node.js >= 12 is required to run this package. If you can't upgrade, you can use [nvm](https://github.com/nvm-sh/nvm) to have [different node versions on your computer](https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/)
143
- - If you do not have java 17 installed on your computer, npm-groovy-lint will install them for you, so the first run may be long.
157
+ - Java 17 or higher is required. If you do not have a compatible Java version installed on your computer, npm-groovy-lint will install Java 17 for you, so the first run may be long.
144
158
 
145
159
  ## Configuration
146
160
 
@@ -398,9 +412,15 @@ Run with additional flags by simply appending them at after docker image name:
398
412
  docker run --rm -u "$(id -u):$(id -g)" -w=/tmp -v "$PWD":/tmp nvuillam/npm-groovy-lint --failon warning --verbose
399
413
  ```
400
414
 
415
+ Use the GitHub Container Registry image by replacing the image name:
416
+
417
+ ```shell
418
+ docker run --rm -u "$(id -u):$(id -g)" -w=/tmp -v "$PWD":/tmp ghcr.io/nvuillam/npm-groovy-lint --failon warning --verbose
419
+ ```
420
+
401
421
  ### Other
402
422
 
403
- You can run npm-groovy-lint using its [official docker image](https://hub.docker.com/r/nvuillam/npm-groovy-lint)
423
+ You can run npm-groovy-lint using its [official Docker Hub image](https://hub.docker.com/r/nvuillam/npm-groovy-lint) or its [GHCR image](https://github.com/nvuillam/npm-groovy-lint/pkgs/container/npm-groovy-lint)
404
424
 
405
425
  ## Use as module
406
426
 
@@ -32,16 +32,17 @@ export class CodeNarcCaller {
32
32
 
33
33
  execTimeout = 240000;
34
34
 
35
+ // Java version requirements: minimum 17, maximum 24 (accepts any Java 17+ version)
35
36
  javaCallerOptions = {
36
37
  codeNarcServer: {
37
38
  minimumJavaVersion: 17,
38
- maximumJavaVersion: 17,
39
+ maximumJavaVersion: 24,
39
40
  rootPath: __dirname,
40
41
  jar: "java/CodeNarcServer.jar",
41
42
  },
42
43
  codeNarcJava: {
43
44
  minimumJavaVersion: 17,
44
- maximumJavaVersion: 17,
45
+ maximumJavaVersion: 24,
45
46
  rootPath: __dirname,
46
47
  jar: "java/CodeNarcServer.jar",
47
48
  },
@@ -16,6 +16,7 @@ export class NpmGroovyLintFix {
16
16
  origin = "unknown";
17
17
  format = false;
18
18
  fixRules = null;
19
+ fixRulesExcluded = null;
19
20
  fixableErrors = {};
20
21
  fixedErrorsNumber = 0;
21
22
  fixedErrorsIds = [];
@@ -32,6 +33,10 @@ export class NpmGroovyLintFix {
32
33
  if (this.options.fixrules && this.options.fixrules !== "all") {
33
34
  this.fixRules = this.options.fixrules.split(",");
34
35
  }
36
+ // Load excluded fix rules
37
+ if (this.options.fixrulesexclude && this.options.fixrulesexclude !== "") {
38
+ this.fixRulesExcluded = this.options.fixrulesexclude.split(",").map(s => s.trim()).filter(Boolean);
39
+ }
35
40
  this.format = optionsIn.format === true;
36
41
  this.origin = optionsIn.origin || this.origin;
37
42
  }
@@ -71,11 +76,17 @@ export class NpmGroovyLintFix {
71
76
  this.fixableErrors[fileNm] = [];
72
77
  const fileErrors = this.updatedLintResult.files[fileNm].errors;
73
78
  for (const err of fileErrors) {
79
+ // Check if rule is allowed by include list
80
+ const allowedByInclude = this.fixRules == null || this.fixRules.includes(err.rule) || this.fixRules[0] === "TriggerTestError";
81
+ // Check if rule is excluded
82
+ const excluded = this.fixRulesExcluded && this.fixRulesExcluded.includes(err.rule);
83
+
74
84
  if (
75
85
  (errorIds == null || errorIds.includes(err.id)) &&
76
86
  this.npmGroovyLintRules[err.rule] != null &&
77
87
  this.npmGroovyLintRules[err.rule].fix != null &&
78
- (this.fixRules == null || this.fixRules.includes(err.rule) || this.fixRules[0] === "TriggerTestError")
88
+ allowedByInclude &&
89
+ !excluded
79
90
  ) {
80
91
  // Add fixable error
81
92
  const fixableError = {
@@ -95,6 +106,10 @@ export class NpmGroovyLintFix {
95
106
  // Trigger other fixes if defined in the rule
96
107
  if (this.npmGroovyLintRules[err.rule].triggers) {
97
108
  for (const triggeredRuleName of this.npmGroovyLintRules[err.rule].triggers) {
109
+ // Skip if triggered rule is excluded
110
+ if (this.fixRulesExcluded && this.fixRulesExcluded.includes(triggeredRuleName)) {
111
+ continue;
112
+ }
98
113
  const fixableErrorTriggered = {
99
114
  id: err.id + "_triggered",
100
115
  ruleName: triggeredRuleName,
@@ -119,6 +134,10 @@ export class NpmGroovyLintFix {
119
134
  if (this.format || this.fixRules == null) {
120
135
  const formattingRulesToAlwaysRun = getFormattingRulesToAlwaysRun();
121
136
  for (const formattingRuleName of formattingRulesToAlwaysRun) {
137
+ // Skip if formatting rule is excluded
138
+ if (this.fixRulesExcluded && this.fixRulesExcluded.includes(formattingRuleName)) {
139
+ continue;
140
+ }
122
141
  const rule = this.npmGroovyLintRules[formattingRuleName];
123
142
  const fixableErrorTriggered = {
124
143
  id: "format_triggered",
@@ -173,6 +192,10 @@ export class NpmGroovyLintFix {
173
192
  for (let i = 0; i < this.fixableErrors[fileNm].length; i++) {
174
193
  // Do not use for-of as content can change during the loops
175
194
  const fileFixableError = this.fixableErrors[fileNm][i];
195
+ // Skip if rule is excluded
196
+ if (this.fixRulesExcluded && this.fixRulesExcluded.includes(fileFixableError.ruleName)) {
197
+ continue;
198
+ }
176
199
  if (this.fixRules != null && !this.fixRules.includes(fileFixableError.ruleName) && this.fixRules[0] !== "TriggerTestError") {
177
200
  continue;
178
201
  }
@@ -81,6 +81,7 @@ class NpmGroovyLint {
81
81
  {
82
82
  verbose: optns.verbose || this.options.verbose,
83
83
  fixrules: optns.fixrules || this.options.fixrules,
84
+ fixrulesexclude: optns.fixrulesexclude || this.options.fixrulesexclude,
84
85
  source: optns.source || this.options.source,
85
86
  save: this.tmpGroovyFileName ? false : true,
86
87
  },
@@ -311,6 +312,7 @@ class NpmGroovyLint {
311
312
  this.fixer = new NpmGroovyLintFix(this.lintResult, {
312
313
  format: this.options.format === true,
313
314
  fixrules: this.options.fixrules,
315
+ fixrulesexclude: this.options.fixrulesexclude,
314
316
  source: this.options.source,
315
317
  save: this.tmpGroovyFileName ? false : true,
316
318
  origin: this.origin,
@@ -386,6 +388,16 @@ class NpmGroovyLint {
386
388
  fixRules.push(...filesAndRulesToProcess[file].fixrules);
387
389
  }
388
390
  fixRules = [...new Set(fixRules)]; // Remove duplicates
391
+ // If there are excluded rules, filter them out from the fixRules list
392
+ if (this.options.fixrulesexclude) {
393
+ const excludedRules = this.options.fixrulesexclude.split(",").map(s => s.trim()).filter(Boolean);
394
+ fixRules = fixRules.filter(rule => !excludedRules.includes(rule));
395
+ }
396
+ // If all rules were excluded, don't run fixAgainAfterFix
397
+ if (fixRules.length === 0) {
398
+ debug(`All triggered rules are excluded, skipping fixAgainAfterFix`);
399
+ return;
400
+ }
389
401
  if (this.options.source) {
390
402
  fixAgainOptions.source = this.lintResult.files[0].updatedSource;
391
403
  }
package/lib/options.js CHANGED
@@ -74,6 +74,14 @@ export const optionsDefinition = optionator({
74
74
  description: "Option for --fix argument: List of rule identifiers to fix (if not specified, all available fixes will be applied)",
75
75
  example: ["SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"],
76
76
  },
77
+ {
78
+ option: "fixrulesexclude",
79
+ type: "String",
80
+ default: "",
81
+ dependsOn: ["fix"],
82
+ description: "Option for --fix argument: Comma-separated list of rule identifiers to exclude from fixes (if not specified, none are excluded). Can be combined with --fixrules",
83
+ example: ["Indentation,IndentationClosingBraces", "UnnecessarySemicolon,SpaceAfterComma"],
84
+ },
77
85
  {
78
86
  option: "ignorepattern",
79
87
  alias: "i",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-groovy-lint",
3
- "version": "16.0.1",
3
+ "version": "16.1.2-beta-202601241018.0",
4
4
  "description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
5
5
  "exports": "./lib/groovy-lint.js",
6
6
  "type": "module",
@@ -60,7 +60,7 @@
60
60
  "fs-extra": "^11.0.0",
61
61
  "glob": "^13.0.0",
62
62
  "import-fresh": "^3.2.1",
63
- "java-caller": "^4.2.1",
63
+ "java-caller": "^4.3.2",
64
64
  "js-yaml": "^4.1.0",
65
65
  "node-sarif-builder": "^3.3.1",
66
66
  "optionator": "^0.9.0",
@@ -75,7 +75,7 @@
75
75
  "adm-zip": "^0.5.10",
76
76
  "diff": "^8.0.0",
77
77
  "eslint": "^9.0.0",
78
- "globals": "^16.0.0",
78
+ "globals": "^17.0.0",
79
79
  "handlebars": "^4.7.8",
80
80
  "mocha": "^11.0.0",
81
81
  "npm-run-all2": "^8.0.0",