Skip to content

Commit

Permalink
feat(linter): add support eslint 9 --quiet param
Browse files Browse the repository at this point in the history
closes #28291
  • Loading branch information
pumano committed Nov 4, 2024
1 parent 38448da commit d13b66f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jest.mock('eslint/use-at-your-own-risk', () => ({
}));

const { LegacyESLint } = require('eslint/use-at-your-own-risk');
import { resolveAndInstantiateESLint } from './eslint-utils';
import { getESLintVersion, resolveAndInstantiateESLint } from './eslint-utils';

describe('eslint-utils', () => {
beforeEach(() => {
Expand Down
9 changes: 8 additions & 1 deletion packages/eslint/src/executors/lint/utility/eslint-utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d13b66f

Please sign in to comment.