Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"executors": "./executors.json",
"peerDependencies": {
"@zkochan/js-yaml": "0.0.7",
"eslint": "^8.0.0 || ^9.0.0"
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
},
"dependencies": {
"@nx/devkit": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.mock('eslint', () => ({}));

jest.mock('eslint/use-at-your-own-risk', () => ({
LegacyESLint: jest.fn(),
}));
Expand Down
21 changes: 16 additions & 5 deletions packages/eslint/src/utils/resolve-eslint-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ export async function resolveESLintClass(opts?: {
useFlatConfigOverrideVal: boolean;
}): Promise<typeof ESLint> {
try {
const shouldESLintUseFlatConfig =
typeof opts?.useFlatConfigOverrideVal === 'boolean'
? opts.useFlatConfigOverrideVal
: useFlatConfig();

// In eslint 8.57.0 (the final v8 version), a dedicated API was added for resolving the correct ESLint class.
const eslintModule = (await import('eslint')) as typeof import('eslint') & {
loadESLint?: (opts: { useFlatConfig: boolean }) => Promise<typeof ESLint>;
};

if (typeof eslintModule.loadESLint === 'function') {
return await eslintModule.loadESLint({
useFlatConfig: shouldESLintUseFlatConfig,
});
}

// Explicitly use the FlatESLint and LegacyESLint classes here because the ESLint class points at a different one based on ESLint v8 vs ESLint v9
// But the decision on which one to use is not just based on the major version of ESLint.
// @ts-expect-error The may be wrong based on our installed eslint version
const { LegacyESLint, FlatESLint } = await import(
'eslint/use-at-your-own-risk'
);

const shouldESLintUseFlatConfig =
typeof opts?.useFlatConfigOverrideVal === 'boolean'
? opts.useFlatConfigOverrideVal
: useFlatConfig();

return shouldESLintUseFlatConfig ? FlatESLint : LegacyESLint;
} catch {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.