-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.base.js
444 lines (424 loc) · 13.6 KB
/
.eslintrc.base.js
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
"use strict";
module.exports = (projectRoot, extraRules = {}) => ({
root: true, // fix possible "Plugin %s was conflicted between %s.json and %s.json" errors
env: {
jest: true,
browser: true,
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:import/recommended",
],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: projectRoot,
project: "tsconfig.json",
warnOnUnsupportedTypeScriptVersion: false,
},
plugins: [
"@typescript-eslint",
"import",
"lodash",
"node",
"react-hooks",
"react",
"typescript-enum",
"typescript-sort-keys",
"unused-imports",
"no-only-tests",
],
settings: {
react: {
version: "detect",
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {
project: projectRoot,
},
},
},
ignorePatterns: [
"node_modules",
"dist",
"webpack.config.ts",
"**/bin/**",
"*.d.ts",
"*.js",
],
rules: {
// TODO: slowly enable no-extraneous-dependencies rule below. For now, it's
// enforced only for some packages.
//
// In an ideal world, the root package.json should have 0 dependencies, and
// all packages/* should define their own dependencies by themselves,
// independently and locally. The rule below is exactly for that: it ensures
// that all package's dependencies are explicitly mentioned in its
// package.json, and no dependencies are borrowed implicitly from the root
// node_modules.
//
// In real life though, enforcing packages independency is dangerous: we may
// e.g. start accidentally bundle 2 React or 2 Redux versions if we forget
// to sync their versions in different monorepo packages' package.json
// files. (There must be some other lint rule for this hopefully.)
//
// In all cases, we should treat node_modules folders content as something
// secondary and transient. (It's true even now with the new "yarn
// Plug-n-Play" technology which we don't use yet.) The source of truth is
// always package.json (enforced by lint) and yarn.lock (defines the exact
// contents of all node_modules folders, bit by bit). In this schema, it
// doesn't matter at all, does yarn use hoisting or not.
//
// "import/no-extraneous-dependencies": "error";
"node/prefer-global/process": "error",
"node/prefer-global/console": "error",
"node/prefer-global/buffer": "error",
"node/prefer-global/url-search-params": "error",
"node/prefer-global/url": "error",
"require-atomic-updates": "off",
"no-prototype-builtins": "off",
"react/prop-types": "off",
"react/no-unescaped-entities": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/promise-function-async": "error",
"arrow-body-style": ["error", "as-needed"],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-floating-promises": ["error", { ignoreVoid: false }],
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
"@typescript-eslint/return-await": ["error"],
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
"@typescript-eslint/ban-ts-comment": ["error"],
"@typescript-eslint/no-useless-constructor": ["error"],
"@typescript-eslint/prefer-optional-chain": ["error"],
"@typescript-eslint/consistent-type-imports": ["error"],
"@typescript-eslint/require-array-sort-compare": [
"error",
{ ignoreStringArrays: true },
],
eqeqeq: ["error"],
"object-shorthand": ["error", "always"],
"@typescript-eslint/unbound-method": ["error"],
"@typescript-eslint/no-implicit-any-catch": [
"error",
{ allowExplicitAny: true },
],
"typescript-enum/no-const-enum": ["error"], // not supported in SWC
"@typescript-eslint/naming-convention": [
"error",
{
selector: "variable",
format: ["camelCase", "PascalCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
filter: {
regex: "^__webpack",
match: false,
},
},
],
// Disable in favour of @typescript-eslint/no-unused-vars.
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"@typescript-eslint/member-ordering": [
"error",
{
//
// ATTENTION: the rules here are not simple, mainly because of this:
// https://github.com/typescript-eslint/typescript-eslint/issues/6133
//
// Besides that, we also want contradictory things, like:
//
// 1. Having constructor close to fields definition (because people
// often define fields in the constructor arguments), although it
// logically should've been below static methods.
// 2. Having all abstract things in the class grouped, irregardless on
// their public/protected/private modifiers.
//
default: [
"signature",
"call-signature",
// Typically, class constants (that's why they're on top).
"public-static-field",
"public-static-get",
"public-static-set",
"protected-static-field",
"protected-static-get",
"protected-static-set",
// All concrete fields. What's interesting is that the order we
// emotionally want here for properties is private-protected-public,
// which is the opposite to the order of methods (which is
// public-protected-private). This is likely because the methods are
// bulky, and properties are lean.
"private-static-field",
"private-instance-field",
"public-instance-field",
"public-abstract-field",
"public-abstract-get",
"public-abstract-set",
// Protected fields and methods are grouped, because eslint currently
// doesn't distinguish fields assigned with a lambda FROM methods, and
// we often times expose abstract protected overridable lambdas:
// https://github.com/typescript-eslint/typescript-eslint/issues/6133
"protected-abstract-field",
"protected-abstract-get",
"protected-abstract-set",
"protected-abstract-method",
"public-abstract-method", // the only exception; it's to group all abstract things too
"protected-instance-field",
"protected-constructor",
"protected-static-method",
"protected-instance-get",
"protected-instance-set",
"protected-instance-method",
// Public constructor, instance methods, static methods.
"public-constructor", // often defines more public/protected/private properties, so should be close to fields
"public-static-method",
"public-instance-get",
"public-instance-set",
"public-instance-method",
// Private constructor, instance methods, static methods.
"private-constructor",
"private-static-method",
"private-instance-get",
"private-instance-set",
"private-instance-method",
"private-static-get",
"private-static-set",
],
},
],
"no-constant-condition": ["error", { checkLoops: false }],
"no-buffer-constructor": ["error"],
"no-console": ["error"],
curly: ["error", "all"],
"no-case-declarations": "off",
"padding-line-between-statements": "off",
"@typescript-eslint/padding-line-between-statements": [
"error",
// Force empty lines.
{
blankLine: "always",
prev: ["block", "block-like", "function", "class", "interface", "type"],
next: "*",
},
{
blankLine: "always",
prev: "import",
next: [
"const",
"if",
"let",
"var",
"export",
"function",
"class",
"interface",
"type",
],
},
{
blankLine: "always",
prev: "*",
next: ["function", "class", "interface", "type"],
},
// Allow one-liner functions without extra spacing (hacky):
{ blankLine: "any", prev: "singleline-const", next: "*" },
{ blankLine: "any", prev: "singleline-var", next: "*" },
{ blankLine: "any", prev: "singleline-let", next: "*" },
],
"no-restricted-properties": [
"error",
{
object: "window",
property: "location",
message:
"We use React Router and History to control the location of our web or desktop app. Prefer `useLocation` in React components and `historyFromContext` in Redux Saga.",
},
...(projectRoot.endsWith("client")
? [
{
object: "window",
property: "document",
message: "Please use `useDocument` from `useDocument.tsx`.",
},
...[
"addEventListener",
"removeEventListener",
"getElementById",
"documentElement",
"activeElement",
"querySelectorAll",
].map((property) => ({
object: "document",
property,
message: "Please use `useDocument` from `useDocument.tsx`.",
})),
]
: []),
],
"no-restricted-globals": [
"warn",
{
name: "location",
message:
"We use React Router and History to control the location of our web or desktop app. Prefer `useLocation` in React components and `historyFromContext` in Redux Saga.",
},
],
"no-restricted-syntax": [
"error",
{
selector: (() => {
const RE_BAD = "/([a-z0-9_ ]|^)E[Ii][Dd]|(^|[-_: ])eid/";
return [
`Identifier[name=${RE_BAD}]`,
`Literal[value=${RE_BAD}]`,
`TemplateElement[value.raw=${RE_BAD}]`,
`TSInterfaceDeclaration[id.name=${RE_BAD}]`,
].join(",");
})(),
message:
'Do not use "eid" or "EID" as a part of a name/field/type. Instead, prefer externalID or external_id.',
},
],
"prefer-const": [
"error",
{
destructuring: "all",
},
],
"no-var": "error",
"no-void": "error",
"react/forbid-dom-props": [
"error",
{
forbid: [
{
propName: "style",
message: "Please use CSS Modules instead",
},
],
},
],
"react/forbid-component-props": [
"error",
{
forbid: [
{
propName: "style",
message: "Please use CSS Modules instead",
},
],
},
],
"no-sequences": ["error"],
// Too noisy about `react` and other node_modules
"import/default": 0,
// This complains about React.forwardRef, ReactDOM.render, etc.
"import/no-named-as-default-member": 0,
// This complains about "apollo" exporting ApolloClient as a default and as a
// named import at the same time.
"import/no-named-as-default": 0,
// Does not seem to work well with node_modules
"import/named": 0,
"import/newline-after-import": "error",
"import/order": [
"error",
{
groups: ["builtin", "external", "index", "parent", "sibling"],
pathGroups: [
{
pattern: "./**.module.css",
group: "sibling",
position: "after",
},
{
pattern: "./**.module.scss",
group: "sibling",
position: "after",
},
],
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
"import/no-useless-path-segments": ["error", { noUselessIndex: true }],
"unused-imports/no-unused-imports": "error",
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["react-router"],
message:
"Please use react-router-dom instead, since react-router's useLocation() doesn't work properly with StaticRouter on server side.",
},
],
},
],
// Fixes a common mistake: `a ?? b < c` which feels like `(a ?? b) < c`, but
// actually is `a ?? (b < c)`
"no-mixed-operators": [
"error",
{
allowSamePrecedence: false,
groups: [
["??", "+"],
["??", "-"],
["??", "*"],
["??", "/"],
["??", "%"],
["??", "**"],
["??", "&"],
["??", "|"],
["??", "^"],
["??", "~"],
["??", "<<"],
["??", ">>"],
["??", ">>>"],
["??", "=="],
["??", "!="],
["??", "==="],
["??", "!=="],
["??", ">"],
["??", ">="],
["??", "<"],
["??", "<="],
["??", "&&"],
["??", "||"],
["??", "in"],
["??", "instanceof"],
],
},
],
quotes: ["error", "double", { avoidEscape: true }],
"no-only-tests/no-only-tests": "error",
...extraRules,
},
});