Skip to content

Commit 640724c

Browse files
authored
migrate eslint from old flatConfig compat to modern flatConfig (#13138)
Verified locally by comparing the output of ```sh % yarn eslint --print-config src/core/__tests__/ApolloClient.test.ts >| test.lint % yarn eslint --print-config src/react/hooks/useQuery.ts >| useQuery.lint % yarn eslint --print-config src/core/ApolloClient.ts >| ApolloClient.lint ``` before and after these changes.
1 parent ab7ae42 commit 640724c

6 files changed

Lines changed: 109 additions & 143 deletions

File tree

eslint-local-rules/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
TDataTVariablesOrder,
1818
} from "./generics.ts";
1919

20+
/** @type {import("eslint").ESLint.Plugin['rules']} */
21+
// @ts-ignore - mismatch between different plugin types, but works
2022
export default {
2123
"require-using-disposable": requireUsingDisposable,
2224
"require-disable-act-environment": requireDisableActEnvironment,

eslint.config.mjs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,37 @@ if (!process.features.typescript) {
1515
import path from "node:path";
1616
import { fileURLToPath } from "node:url";
1717

18-
import { fixupPluginRules } from "@eslint/compat";
19-
import { FlatCompat } from "@eslint/eslintrc";
20-
import js from "@eslint/js";
18+
import { defineConfig, globalIgnores } from "eslint/config";
2119
import typescriptEslint from "@typescript-eslint/eslint-plugin";
2220
import tsParser from "@typescript-eslint/parser";
23-
import _import from "eslint-plugin-import";
21+
import importPlugin from "eslint-plugin-import";
2422
import * as mdx from "eslint-plugin-mdx";
2523
import globals from "globals";
2624
import reactHooks from "eslint-plugin-react-hooks";
25+
import testingLibrary from "eslint-plugin-testing-library";
2726

2827
import localRules from "./eslint-local-rules/index.mjs";
2928

3029
const __filename = fileURLToPath(import.meta.url);
3130
const __dirname = path.dirname(__filename);
32-
const compat = new FlatCompat({
33-
baseDirectory: __dirname,
34-
recommendedConfig: js.configs.recommended,
35-
allConfig: js.configs.all,
36-
});
3731

3832
/**
3933
* Some rules can be very costly so we only want to run them from CLI, not from the LSP.
4034
*/
4135
const runExtendedRules = !!process.env.EXTENDED_RULES;
4236

37+
/** @type {Record<string, import("eslint").ESLint.Plugin>} */
4338
const tsPlugins = {
44-
import: fixupPluginRules(_import),
39+
import: importPlugin,
4540
"local-rules": {
4641
rules: localRules,
4742
},
43+
// @ts-ignore - slight mismatch between old and new ESLint plugin types
4844
"@typescript-eslint": typescriptEslint,
4945
};
5046

51-
export default [
47+
export default defineConfig([
48+
globalIgnores(["integration-tests/"]),
5249
{
5350
files: ["**/*.ts", "**/*.tsx"],
5451
plugins: tsPlugins,
@@ -212,16 +209,15 @@ export default [
212209
"local-rules/tdata-tvariables-order": "error",
213210
},
214211
},
215-
...compat.extends("plugin:testing-library/react").map((config) => ({
216-
...config,
217-
212+
{
218213
files: [
219214
"**/__tests__/**/*.[jt]s",
220215
"**/__tests__/**/*.[jt]sx",
221216
"**/?(*.)+(test).[jt]s",
222217
"**/?(*.)+(test).[jt]sx",
223218
],
224-
})),
219+
...testingLibrary.configs["flat/react"],
220+
},
225221
{
226222
files: [
227223
"**/__tests__/**/*.[jt]s",
@@ -290,4 +286,4 @@ export default [
290286
basePath: "docs",
291287
...mdx.flatCodeBlocks,
292288
},
293-
];
289+
]);

jsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"checkJs": true,
4+
"strict": true,
5+
"noImplicitAny": true,
6+
"module": "nodenext",
7+
"moduleResolution": "nodenext",
8+
"allowImportingTsExtensions": true
9+
},
10+
"include": ["**/*.js", "**/*.mjs"]
11+
}

knip.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const scriptEntries = Array.from(
2222
/** @type{import('knip').KnipConfig}*/
2323
const config = {
2424
exclude: ["optionalPeerDependencies", "unresolved"],
25-
entry: []
25+
entry: /**@type {string[]}*/ ([])
2626
.concat(packageEntries)
2727
.concat(scriptEntries)
2828
.concat([

0 commit comments

Comments
 (0)