Skip to content

Commit 8aa8c55

Browse files
authored
chore: update eslint (#14899)
1 parent b192994 commit 8aa8c55

12 files changed

Lines changed: 1585 additions & 506 deletions

File tree

.eslintrc

Lines changed: 0 additions & 96 deletions
This file was deleted.
File renamed without changes.

eslint.config.ts

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
import { createRequire } from "node:module";
2+
import { fixupPluginRules } from "@eslint/compat";
3+
import { defineConfig } from "eslint/config";
4+
5+
const require = createRequire(import.meta.url);
6+
const eslintRequire = createRequire(require.resolve("eslint/package.json"));
7+
8+
const globals = eslintRequire("globals");
9+
const reactAppConfig = require("eslint-config-react-app");
10+
11+
const flowtypePlugin = fixupPluginRules(require("eslint-plugin-flowtype"));
12+
const importPlugin = fixupPluginRules(require("eslint-plugin-import"));
13+
const jestPlugin = fixupPluginRules(require("eslint-plugin-jest"));
14+
const jsdocPlugin = fixupPluginRules(require("eslint-plugin-jsdoc"));
15+
const jsxA11yPlugin = fixupPluginRules(require("eslint-plugin-jsx-a11y"));
16+
const reactPlugin = fixupPluginRules(require("eslint-plugin-react"));
17+
const reactHooksPlugin = fixupPluginRules(require("eslint-plugin-react-hooks"));
18+
const tsEslintPlugin = fixupPluginRules(
19+
require("@typescript-eslint/eslint-plugin"),
20+
);
21+
const tsParser = require("@typescript-eslint/parser");
22+
23+
const reactAppTsOverride = reactAppConfig.overrides.find(
24+
(config: { files?: string[] }) => config.files?.includes("**/*.ts?(x)"),
25+
);
26+
27+
if (!reactAppTsOverride) {
28+
throw new Error("Could not find the react-app TypeScript override.");
29+
}
30+
31+
const jestRecommended = jestPlugin.configs["flat/recommended"];
32+
33+
function normalizeGlobals(globalsToNormalize: Record<string, unknown>) {
34+
return Object.fromEntries(
35+
Object.entries(globalsToNormalize).map(([name, value]) => [
36+
name.trim(),
37+
value,
38+
]),
39+
);
40+
}
41+
42+
function disableGlobals(globalsToDisable: Record<string, unknown>) {
43+
return Object.fromEntries(
44+
Object.keys(globalsToDisable).map((name) => [name, "off"] as const),
45+
);
46+
}
47+
48+
const codeFiles = ["**/*.{js,mjs,cjs,jsx,ts,tsx}"];
49+
const reactRouterFiles = ["packages/react-router/**/*.{js,mjs,cjs,jsx,ts,tsx}"];
50+
const browserGlobals = normalizeGlobals(globals.browser);
51+
const commonJsGlobals = normalizeGlobals(globals.commonjs);
52+
const nodeGlobals = normalizeGlobals(globals.node);
53+
const jestGlobals = normalizeGlobals(globals.jest);
54+
55+
export default defineConfig([
56+
{
57+
ignores: [
58+
"fixtures/**",
59+
"node_modules/**",
60+
"pnpm-lock.yaml",
61+
"docs/api/**",
62+
"examples/**/dist/**",
63+
"worker-configuration.d.ts",
64+
"playground/**",
65+
"playground-local/**",
66+
"integration/helpers/**/dist/**",
67+
"integration/helpers/**/build/**",
68+
"playwright-report/**",
69+
"test-results/**",
70+
"build.utils.d.ts",
71+
".wrangler/**",
72+
"**/.wrangler/**",
73+
".tmp/**",
74+
".react-router/**",
75+
"**/.react-router/**",
76+
"packages/**/dist/**",
77+
"packages/react-router-dom/server.d.ts",
78+
"packages/react-router-dom/server.js",
79+
"packages/react-router-dom/server.mjs",
80+
"tutorial/dist/**",
81+
"public/**",
82+
],
83+
},
84+
{
85+
linterOptions: {
86+
reportUnusedDisableDirectives: "warn",
87+
},
88+
},
89+
{
90+
files: codeFiles,
91+
languageOptions: {
92+
parserOptions: {
93+
ecmaVersion: "latest",
94+
sourceType: "module",
95+
ecmaFeatures: {
96+
jsx: true,
97+
},
98+
},
99+
globals: {
100+
...browserGlobals,
101+
...commonJsGlobals,
102+
...nodeGlobals,
103+
...jestGlobals,
104+
},
105+
},
106+
plugins: {
107+
flowtype: flowtypePlugin,
108+
import: importPlugin,
109+
"jsx-a11y": jsxA11yPlugin,
110+
react: reactPlugin,
111+
"react-hooks": reactHooksPlugin,
112+
},
113+
settings: {
114+
react: {
115+
version: "detect",
116+
},
117+
},
118+
rules: {
119+
...reactAppConfig.rules,
120+
"import/first": "off",
121+
"react/jsx-uses-react": "warn",
122+
"react/jsx-uses-vars": "warn",
123+
},
124+
},
125+
{
126+
files: ["**/*.{ts,tsx}"],
127+
languageOptions: {
128+
parser: tsParser,
129+
parserOptions: {
130+
ecmaVersion: "latest",
131+
sourceType: "module",
132+
ecmaFeatures: {
133+
jsx: true,
134+
},
135+
warnOnUnsupportedTypeScriptVersion: true,
136+
},
137+
},
138+
plugins: {
139+
"@typescript-eslint": tsEslintPlugin,
140+
},
141+
rules: {
142+
...reactAppTsOverride.rules,
143+
"@typescript-eslint/consistent-type-imports": [
144+
"error",
145+
{
146+
disallowTypeAnnotations: false,
147+
},
148+
],
149+
},
150+
},
151+
{
152+
files: ["**/__tests__/**/*.{js,mjs,cjs,jsx,ts,tsx}"],
153+
plugins: {
154+
jest: jestPlugin,
155+
},
156+
languageOptions: jestRecommended.languageOptions,
157+
rules: jestRecommended.rules,
158+
},
159+
{
160+
files: ["integration/**/*.{js,mjs,cjs,jsx,ts,tsx}"],
161+
languageOptions: {
162+
globals: disableGlobals(jestGlobals),
163+
},
164+
rules: {
165+
"react-hooks/rules-of-hooks": "off",
166+
},
167+
},
168+
{
169+
files: reactRouterFiles,
170+
rules: {
171+
strict: "off",
172+
"import/no-nodejs-modules": "error",
173+
"no-restricted-globals": [
174+
"error",
175+
{
176+
name: "__dirname",
177+
message: "Node globals are not allowed in this package.",
178+
},
179+
{
180+
name: "__filename",
181+
message: "Node globals are not allowed in this package.",
182+
},
183+
{
184+
name: "Buffer",
185+
message: "Node globals are not allowed in this package.",
186+
},
187+
],
188+
},
189+
},
190+
{
191+
files: ["packages/react-router/__tests__/**/*.{js,mjs,cjs,jsx,ts,tsx}"],
192+
rules: {
193+
"import/no-nodejs-modules": "off",
194+
"no-console": "off",
195+
"no-restricted-globals": "off",
196+
},
197+
},
198+
{
199+
files: [
200+
"packages/react-router/lib/server-runtime/**/*.{js,mjs,cjs,jsx,ts,tsx}",
201+
],
202+
rules: {
203+
"no-restricted-syntax": "off",
204+
},
205+
},
206+
{
207+
files: ["packages/react-router-dev/config/default-rsc-entries/*"],
208+
rules: {
209+
"@typescript-eslint/consistent-type-imports": "off",
210+
},
211+
},
212+
{
213+
files: [
214+
"packages/react-router/lib/components.tsx",
215+
"packages/react-router/lib/hooks.tsx",
216+
"packages/react-router/lib/dom/lib.tsx",
217+
"packages/react-router/lib/dom/ssr/components.tsx",
218+
"packages/react-router/lib/dom/ssr/server.tsx",
219+
"packages/react-router/lib/dom-export/hydrated-router.tsx",
220+
"packages/react-router/lib/dom/server.tsx",
221+
"packages/react-router/lib/router/utils.ts",
222+
"packages/react-router/lib/rsc/browser.tsx",
223+
"packages/react-router/lib/rsc/server.rsc.ts",
224+
"packages/react-router/lib/rsc/server.ssr.tsx",
225+
"packages/react-router/lib/rsc/html-stream/browser.ts",
226+
],
227+
plugins: {
228+
jsdoc: jsdocPlugin,
229+
},
230+
rules: {
231+
"jsdoc/check-access": "error",
232+
"jsdoc/check-alignment": "error",
233+
"jsdoc/check-param-names": "error",
234+
"jsdoc/check-property-names": "error",
235+
"jsdoc/check-tag-names": [
236+
"error",
237+
{
238+
definedTags: ["additionalExamples", "category", "mode"],
239+
},
240+
],
241+
"jsdoc/no-defaults": "error",
242+
"jsdoc/no-multi-asterisks": ["error", { allowWhitespace: true }],
243+
"jsdoc/require-description": "error",
244+
"jsdoc/require-param": ["error", { enableRootFixer: false }],
245+
"jsdoc/require-param-description": "error",
246+
"jsdoc/require-param-name": "error",
247+
"jsdoc/require-returns": "error",
248+
"jsdoc/require-returns-check": "error",
249+
"jsdoc/require-returns-description": "error",
250+
"jsdoc/sort-tags": [
251+
"error",
252+
{
253+
tagSequence: [
254+
{
255+
tags: ["description"],
256+
},
257+
{
258+
tags: ["example"],
259+
},
260+
{
261+
tags: ["additionalExamples"],
262+
},
263+
{
264+
tags: [
265+
"name",
266+
"public",
267+
"private",
268+
"category",
269+
"mode",
270+
"param",
271+
"returns",
272+
],
273+
},
274+
],
275+
},
276+
],
277+
},
278+
},
279+
]);

0 commit comments

Comments
 (0)