feat(linter): add support eslint 9 --quiet param (#28743)

closes #28291

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
eslint 9 support --quiet param for not run warn rules, but nx not pass
that param directly
## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
nx executor should pass --quiet directly to eslint
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28291
This commit is contained in:
Dmitry Zakharov 2024-11-05 00:15:59 +03:00 committed by GitHub
parent dbabfa7d2c
commit bb878aa033
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import type { ESLint } from 'eslint';
import { gte } from 'semver';
import { isFlatConfig } from '../../../utils/config-file';
import { resolveESLintClass } from '../../../utils/resolve-eslint-class';
import type { Schema } from '../schema';
@ -18,7 +19,8 @@ export async function resolveAndInstantiateESLint(
useFlatConfigOverrideVal: useFlatConfig,
});
const eslintOptions: ESLint.Options = {
// ruleFilter exist only in eslint 9+, remove this type when eslint 8 support dropped
const eslintOptions: ESLint.Options & { ruleFilter?: Function } = {
overrideConfigFile: eslintConfigPath,
fix: !!options.fix,
cache: !!options.cache,
@ -72,6 +74,11 @@ export async function resolveAndInstantiateESLint(
options.reportUnusedDisableDirectives || undefined;
}
// pass --quiet to eslint 9+ directly: filter only errors
if (options.quiet && gte(ESLint.version, '9.0.0')) {
eslintOptions.ruleFilter = (rule) => rule.severity === 2;
}
const eslint = new ESLint(eslintOptions);
return {