-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.js
438 lines (431 loc) · 12.4 KB
/
default.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
module.exports = {
"env": {
"es2022": true,
"node": true,
"browser": true,
"worker": true,
"serviceworker": true,
},
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module",
},
"plugins": [
"unicorn",
"import",
"regexp",
],
"extends": [
"eslint:recommended",
"plugin:unicorn/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:regexp/recommended",
],
// Lint all files using these extension patterns
// - Lets ESLint v7 know to add these to `--ext`
"overrides": [
{
"files": [
"**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
],
},
],
"ignorePatterns": [
/*
Disable existing ignores for lintable files
- `{List}` glob patters do not override ESLint's defaults
- Doesn't enable tool-dependent filenames line `.babelrc`
- Out of scope, rename the file or use ignore/overrides
*/
"!**/.*.js",
"!**/.*.cjs",
"!**/.*.mjs",
"!**/.*.ts",
"!**/.*.cts",
"!**/.*.mts",
"!**/.*.jsx",
"!**/.*.tsx",
],
"rules": {
/*
ESLint rules
Supported rules: https://eslint.org/docs/rules/
*/
// Tabs > spaces
// Reason: Style and accessibility
// Learn more in this Reddit and Twitter thread: https://twitter.com/sarah_federman/status/1146544481556033537
"indent": [
"error",
"tab",
{
// Reason: Indent in switch cases to match the common styling
"SwitchCase": 1,
// Reason: Ignore JSX, use `evelyn/react` rules instead
"ignoredNodes": [
"JSXElement", "JSXElement > *", "JSXAttribute", "JSXIdentifier", "JSXNamespacedName", "JSXMemberExpression", "JSXSpreadAttribute", "JSXExpressionContainer", "JSXOpeningElement", "JSXClosingElement", "JSXFragment", "JSXOpeningFragment", "JSXClosingFragment", "JSXText", "JSXEmptyExpression", "JSXSpreadChild",
],
},
],
// Reason: Consistent spacing in comments for readability
"spaced-comment": [
"error",
"always",
{
// Reason: Allow TypeScript triple slash directives
"markers": ["/"],
},
],
// Reason: Line breaks should be committed as the near-universal `LF` characters to prevent excess whitespace diffing
// - Only turn this off if you trust your team's auto-crlf configs or have a hook check for this
"linebreak-style": [
"error",
"unix",
],
// Reason: Avoid extra whitespace diffing when modifying files
// Preferring always because of the legacy of unix files
"eol-last": "error",
// Reason: Empty lines can be helpful in the middle of code to organize longer modules, but extra shouldn't show up at the beginning or end
"no-multiple-empty-lines": [
"error",
{
"max": 3,
"maxEOF": 0,
"maxBOF": 0,
},
],
// Reason: Consistent hugging of blocks
"block-spacing": [
"error",
"never",
],
"object-curly-spacing": [
"error",
"never",
],
"brace-style": "error",
"padded-blocks": [
"error",
"never",
],
"space-in-parens": [
"error",
"never",
],
"space-before-function-paren": [
"error",
"always",
],
"space-before-blocks": [
"error",
"always",
],
"func-call-spacing": "error",
"keyword-spacing": "error",
"arrow-spacing": [
"error",
{
"before": true,
"after": true,
},
],
"rest-spread-spacing": [
"error",
"never",
],
"template-curly-spacing": [
"error",
"never",
],
"key-spacing": "error",
"comma-spacing": [
"error",
{
"before": false,
"after": true,
},
],
"space-infix-ops": "error",
"no-multi-spaces": "error",
// Reason: Avoid extra visual noise
"no-useless-rename": "error",
"prefer-destructuring": "error",
// Double quotes are bae (templates ok)
// Reason: Easier to spot and support apostrophes
"quotes": [
"error",
"double",
{
// Reason: Allow avoiding extra escapes by using other quotes
"avoidEscape": true,
// Reason: Allow all template literals as an alternative option to single quotes
"allowTemplateLiterals": true,
},
],
// Reason: Avoid using quotes that can't be copied from other languages like HTML
"jsx-quotes": [
"error",
"prefer-double",
],
// Reason: Missing a semicolon can break code in unexpected ways
// - `const object = {value: 100}/* \n */(() => console.log(object))()` will fail with a confusing error message, for instance
"semi": [
"error",
"always",
],
"no-extra-semi": "warn",
// Reason: `var`'s function scope can cause unexpected results
// - Explicitly hoist variables with `let` or `const` instead
"no-var": "error",
// Reason: `const` is a helpful guide, even if not frozen
"prefer-const": "error",
// Reason: Console commands should be explicitly allowed with an eslint-disable no-console comment to prevent hard to read consoles or memory leaks
"no-console": "warn",
// Reason: Alert is blocking, and any use of it will soon be pushed to deprecate by Chrome
"no-alert": "error",
// Reason: Throw error instances instead
"no-throw-literal": "error",
// Reason: Add object key quotes when it could conflict with a a reserved word or number
"quote-props": [
"warn",
"as-needed",
{
"unnecessary": false,
"numbers": true,
},
],
// Reason: Ease of moving and sorting lines without extra visual noise
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
// Can be unexpected in single param functions like `render()` in testing library
"functions": "only-multiline",
},
],
// Reason: Allow omitting vars from objects like `{badProp, ...otherProps} = props`
"no-unused-vars": [
"error",
{
"ignoreRestSiblings": true,
},
],
// Reason: Most likely a performance issue that can be dramatic on a frontend
"no-await-in-loop": "error",
// Reason: Helps catch errors with forgetting to
// - Avoids the classic `Hello ${firstName}` meme from marketing emails
"no-template-curly-in-string": "error",
// Reason: Suggest dot notation for valid literals
"dot-notation": "error",
// Reason: Enforce strict equals except for doing nullish checks
"eqeqeq": [
"error",
"always",
{
"null": "ignore",
},
],
// Reason: Named capture groups are stable and help finding the correct group and making regex self-documenting
"prefer-named-capture-group": "error",
// Reason: Not in strict mode
"no-caller": "error",
// Possible errors
"no-extend-native": "error",
"no-proto": "error",
"no-iterator": "error",
"no-self-compare": "error",
"no-useless-call": "error",
"radix": "error",
"require-await": "error",
"no-unused-expressions": [
"error",
{
"allowShortCircuit": true,
"allowTernary": true,
"allowTaggedTemplates": true,
},
],
"no-array-constructor": "error",
"no-fallthrough": [
"error",
{
"commentPattern": "falls?\\s?through|break",
},
],
// Reason: unicorn implements a version ignoring hashbanged files
"no-process-exit": "off",
/*
Regexp rules
Supported rules: https://ota-meshi.github.io/eslint-plugin-regexp/rules
*/
// Reason: Removing `target: all` since literals are more readable for uncommon Unicode characters
"regexp/prefer-range": [
"error",
{
"target": "alphanumeric",
},
],
/*
Unicorn rules
Supported rules: https://github.com/sindresorhus/eslint-plugin-unicorn#rules
*/
// Reason: Enabled in ESM config for incremental adoption
"unicorn/prefer-module": "off",
// Reason: `forEach` is helpfully functional sometimes
"unicorn/no-array-for-each": "off",
// Reason: React references, null handling tests, and nullish checks should be able to use null
"unicorn/no-null": "off",
// Reason: Sometimes `Array.from()` is more readable
"unicorn/prefer-spread": "off",
// Reason: Other APIs offer more performance and simplicity in some cases
"unicorn/prefer-query-selector": "off",
// Reason: In cases like event handlers that don't need a closure scope, it isn't critical to hoist the handler out of the component for a tiny bit of performance
"unicorn/consistent-function-scoping": [
"error",
{
"checkArrowFunctions": false,
},
],
// Reason: Abbreviations are hard to understand when you aren't the original author
// - Example: `<img onError={(e) => {}} />` where `e` could be confused for `element` or `error`, when it is an `event` in React
// - Includes defaults and excludes items in the allow list
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
// Reason: Add `element` as a suggestion
"e": {
"error": true,
"event": true,
"element": true,
},
// Reason: `props` is a term used more often than properties in React
"props": false,
"prop": false,
// Reason: `ref` is a term used more often than reference in React
"ref": false,
// Reason: `arguments` is a reserved word and Storybook documentation API
"args": false,
"arg": false,
// Reason: Reflective of `args` and `props`, `params` should also be allowed
"param": false,
"params": false,
},
"ignore": [
// Reason: React Scripts doesn't check for other filenames for the type reference file
/^react-app-env(?:\.d)?$/,
],
},
],
// Reason: Length comparison checks are often needlessly verbose, especially with optional chaining
"unicorn/explicit-length-check": "off",
// Reason: Enforce the use of issues or expiring-todo-comments
"unicorn/expiring-todo-comments": [
"error",
{
"allowWarningComments": false,
},
],
// Reason: Reduce is hard to understand and refactor, but sometimes it's the best tool for the job
"unicorn/no-array-reduce": "off",
// Reason: Creating own handler functions
"unicorn/no-fn-reference-in-iterator": "off",
// Reason: Creating own handler functions
"unicorn/no-array-callback-reference": "off",
// Reason: Consistency using PascalCase for components and kebab-case for everything else
"unicorn/filename-case": [
"error",
{
"cases": {
// Most files
"kebabCase": true,
// Single export React component files
"pascalCase": true,
},
"ignore": [
"^[A-Z][a-zA-Z]+\\.[a-z\\.\\-]+$", // Allow all caps inside PascalCase for React components with initialisms (e.g. PageSEO.jsx)
],
},
],
// Reason: Unicorn's import style is too opinionated
"unicorn/import-style": "off",
// Reason: Ternary expressions are harder for beginners to read
"unicorn/prefer-ternary": "off",
// Reason: Remove unused `undefined`
"unicorn/no-useless-undefined": [
"error",
{
// Reason: TypeScript will expect explicit `undefined` in some call signatures
"checkArguments": false,
},
],
// Reason: Fallthrough default cases help create self documenting branching
"unicorn/no-useless-switch-case": "off",
/*
Import rules
Supported rules: https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
*/
// Reason: Don't use @deprecated exports
"import/no-deprecated": "error",
// Reason: Import organization style
"import/no-useless-path-segments": "error",
"import/first": "error",
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true,
},
// Force React to the top of external
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before",
},
],
"pathGroupsExcludedImportTypes": ["builtin"],
},
],
"import/newline-after-import": [
"error",
{
"count": 1,
},
],
// Reason: Mutating exports isn't expected behavior
"import/no-mutable-exports": "warn",
// Reason: Avoid exporting functions without names for stack tracing and confusing syntax
"import/no-anonymous-default-export": [
"error", {
"allowArray": true,
"allowArrowFunction": false, // Needs a stacktrace name
"allowAnonymousClass": false, // Needs a stacktrace name
"allowAnonymousFunction": false, // Needs a stacktrace name
"allowCallExpression": false, // Can be confused with an exported function
"allowLiteral": true,
"allowObject": true,
},
],
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".cjs", ".mjs", ".jsx", ".ts", ".cts", ".mts", ".tsx"],
},
"typescript": {
"alwaysTryTypes": true,
"project": "tsconfig.json",
},
},
// Worker modules using `worker-loader`
"import/ignore": [
"\\.worker(\\.(j|t)s)?$",
],
},
};