npm-groovy-lint 16.0.0 → 16.1.1

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
@@ -449,8 +449,8 @@ async function buildRuleSets(options) {
449
449
  ? ruleOptions
450
450
  : ruleFromConfig;
451
451
  const ruleDef = buildCodeNarcRule(ruleName, mergedRuleConfig);
452
- // If rule has been sent as argument, enable it by default
453
- if (ruleDef.enabled === false) {
452
+ // If rule has been sent as argument, enable it if not explicitly disabled
453
+ if (ruleOptions.enabled !== false && ruleDef.enabled === false) {
454
454
  ruleDef.enabled = true;
455
455
  }
456
456
  return ruleDef;
@@ -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.0",
3
+ "version": "16.1.1",
4
4
  "description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
5
5
  "exports": "./lib/groovy-lint.js",
6
6
  "type": "module",