-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy patheslint.config.mjs
More file actions
289 lines (267 loc) · 7.69 KB
/
eslint.config.mjs
File metadata and controls
289 lines (267 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
if (!process.features.typescript) {
throw new Error(
`
This configuration requires TypeScript support.
Run node with --experimental-strip-types.
If using VSCode, add the following to your settings.json
and reload the window (restarting the ESLint Server might not be enough):
"eslint.runtime": "/opt/homebrew/bin/node",
"eslint.execArgv": [ "--experimental-strip-types" ]
`
);
}
import path from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig, globalIgnores } from "eslint/config";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import importPlugin from "eslint-plugin-import";
import * as mdx from "eslint-plugin-mdx";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import testingLibrary from "eslint-plugin-testing-library";
import localRules from "./eslint-local-rules/index.mjs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Some rules can be very costly so we only want to run them from CLI, not from the LSP.
*/
const runExtendedRules = !!process.env.EXTENDED_RULES;
/** @type {Record<string, import("eslint").ESLint.Plugin>} */
const tsPlugins = {
import: importPlugin,
"local-rules": {
rules: localRules,
},
// @ts-ignore - slight mismatch between old and new ESLint plugin types
"@typescript-eslint": typescriptEslint,
};
export default defineConfig([
globalIgnores(["integration-tests/"]),
{
files: ["**/*.ts", "**/*.tsx"],
plugins: tsPlugins,
ignores: ["tests.codegen.ts"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parser: tsParser,
ecmaVersion: "latest",
sourceType: "commonjs",
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/internal-regex": "^@apollo/client",
"import/resolver": {
typescript: {
alwaysTryTypes: true,
},
},
},
// rules for the whole repo
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "@wry/equality",
importNames: ["default"],
message:
"Please use named export `{ equal }` from @wry/equality instead.",
},
],
},
],
"import/no-unresolved": "error",
"import/order": [
"warn",
{
"newlines-between": "always",
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
alphabetize: {
order: "asc",
orderImportKind: "asc",
caseInsensitive: true,
},
named: true,
},
],
"local-rules/import-from-export": "error",
"local-rules/import-from-inside-other-export": [
"warn",
{
ignoreFrom: [
"src/version.js",
"src/invariantErrorCodes.js",
"src/utilities/caching/getMemoryInternals.js",
"src/utilities/types/TODO.js",
"src/utilities/caching/sizes.js",
].map((file) => path.resolve(__dirname, file)),
},
],
"local-rules/no-duplicate-exports": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
disallowTypeAnnotations: false,
fixStyle: "separate-type-imports",
},
],
"@typescript-eslint/no-namespace": [
"error",
{
allowDeclarations: true,
},
],
},
},
{
...reactHooks.configs.flat["recommended-latest"],
files: ["src/react/**/*.ts", "src/react/**/*.tsx"],
ignores: ["**/__tests__/**/*.*", "**/*.d.ts"],
},
{
files: ["**/*.ts", "**/*.tsx"],
ignores: ["**/__tests__/**/*.*", "**/*.d.ts"],
plugins: {
...tsPlugins,
},
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
parserOptions: {
project: [
"./tsconfig.json",
"./codegen/tsconfig.json",
"./config/tsconfig.json",
"./docs/tsconfig.json",
"./eslint-local-rules/tsconfig.json",
"./scripts/codemods/data-masking/tsconfig.json",
"./scripts/codemods/ac3-to-ac4/tsconfig.json",
],
},
},
// rules for source files, but no tests
rules: {
"@typescript-eslint/consistent-type-exports": ["error"],
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/no-restricted-types": [
"error",
{
types: {
GraphQLError: {
message: "Use GraphQLFormattedError instead",
fixWith: "GraphQLFormattedError",
},
ExecutionResult: {
message: "Use FormattedExecutionResult instead",
fixWith: "FormattedExecutionResult",
},
},
},
],
"no-restricted-syntax": [
"error",
{
selector:
"ImportDeclaration[source.value='react'][importKind!='type'] :matches(ImportSpecifier, ImportDefaultSpecifier)",
message:
"Please only use the namespace import syntax (`import * as React from 'react'`) for React imports!",
},
"ExportAllDeclaration",
],
"import/consistent-type-specifier-style": ["error", "prefer-top-level"],
"local-rules/require-using-disposable": "error",
"local-rules/valid-inherit-doc": "error",
"local-rules/variables-should-extend-operation-variables": "error",
"local-rules/tdata-tvariables-order": "error",
},
},
{
files: [
"**/__tests__/**/*.[jt]s",
"**/__tests__/**/*.[jt]sx",
"**/?(*.)+(test).[jt]s",
"**/?(*.)+(test).[jt]sx",
],
...testingLibrary.configs["flat/react"],
},
{
files: [
"**/__tests__/**/*.[jt]s",
"**/__tests__/**/*.[jt]sx",
"**/?(*.)+(test).[jt]s",
"**/?(*.)+(test).[jt]sx",
],
plugins: tsPlugins,
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
parserOptions: {
project: [
"./tsconfig.tests.json",
"./eslint-local-rules/tsconfig.json",
"./scripts/codemods/ac3-to-ac4/tsconfig.tests.json",
],
},
},
// rules for tests only
rules: {
"testing-library/prefer-user-event": "error",
"testing-library/no-wait-for-multiple-assertions": "off",
"local-rules/require-using-disposable": "error",
"local-rules/require-disable-act-environment": "error",
"local-rules/forbid-act-in-disabled-act-environment": "error",
"local-rules/import-from-inside-other-export": "off",
"local-rules/no-internal-import-official-export":
runExtendedRules ? "error" : "off",
"local-rules/no-relative-imports": [
"error",
{
ignoreFrom: ["src/utilities/caching/sizes.js"].map((file) =>
path.resolve(__dirname, file)
),
},
],
"import/no-duplicates": "warn",
"@typescript-eslint/no-floating-promises": "warn",
},
},
{
files: ["scripts/codemods/ac3-to-ac4/**/__tests__/**/*.ts"],
// rules for tests only
rules: {
"local-rules/no-relative-imports": "off",
},
},
{
basePath: "docs",
...mdx.flat,
plugins: {
...mdx.flat.plugins,
"local-rules": {
rules: localRules,
},
},
rules: {
"local-rules/mdx-valid-canonical-references": "error",
},
},
{
basePath: "docs",
...mdx.flatCodeBlocks,
},
]);