Skip to content

Commit 59496ed

Browse files
authored
fix(linter): update lint executor to correctly handle --fix and --quiet (#31970)
## Current Behavior When running ESLint using the `@nx/eslint:lint` executor with `--quiet` and `--fix`, and there are errors, no fix is made, and the task incorrectly succeeds. This is a regression introduced by 9406d2b, which updated the executor to not fix warnings when `--quiet` is used, but the solution was incorrect. ## Expected Behavior When running ESLint using the `@nx/eslint:lint` executor with `--quiet` and `--fix`, and there are errors, fixes should be applied, and the task should succeed if there are no remaining errors. It should not fix warnings. ## Related Issue(s) Fixes #31868
1 parent 84a6f9d commit 59496ed

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/eslint/src/executors/lint/lint.impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ Please see https://nx.dev/recipes/tips-n-tricks/eslint for full guidance on how
183183
);
184184
}
185185

186+
// output fixes to disk, if applicable based on the options
187+
await ESLint.outputFixes(lintResults);
188+
186189
// if quiet, only show errors
187190
if (normalizedOptions.quiet) {
188191
console.debug('Quiet mode enabled - filtering out warnings\n');
189192
lintResults = ESLint.getErrorResults(lintResults);
190193
}
191194

192-
// output fixes to disk, if applicable based on the options
193-
await ESLint.outputFixes(lintResults);
194-
195195
const formatter = await eslint.loadFormatter(normalizedOptions.format);
196196

197197
const formattedResults = await formatter.format(lintResults);

packages/eslint/src/executors/lint/utility/eslint-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export async function resolveAndInstantiateESLint(
2222
// ruleFilter exist only in eslint 9+, remove this type when eslint 8 support dropped
2323
const eslintOptions: ESLint.Options & { ruleFilter?: Function } = {
2424
overrideConfigFile: eslintConfigPath,
25-
fix: !!options.fix,
25+
fix:
26+
!!options.fix &&
27+
(options.quiet ? (message) => message.severity === 2 : true),
2628
cache: !!options.cache,
2729
cacheLocation: options.cacheLocation || undefined,
2830
cacheStrategy: options.cacheStrategy || undefined,

0 commit comments

Comments
 (0)