-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eslintrc.js
386 lines (345 loc) · 10.2 KB
/
.eslintrc.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
/* eslint-disable max-lines */
/**
* Common jsdoc formatting rules
*/
const JSDOC_RULES = {
require: {
ArrowFunctionExpression: false,
ClassDeclaration: true,
ClassExpression: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true,
},
contexts: [
{
context: "TSPropertySignature",
inlineCommentBlock: true,
},
"TSEnumDeclaration",
"TSTypeAliasDeclaration",
"FunctionDeclaration",
"ClassDeclaration",
],
};
module.exports = {
globals: {
// Allow for self to be a mirror of window
self: true,
},
parser: "@typescript-eslint/parser",
extends: [
"airbnb-base",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"plugin:jsdoc/recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
"plugin:eslint-comments/recommended",
"next",
"prettier",
"next/core-web-vitals",
],
env: {
browser: true,
node: true,
es6: true,
},
plugins: [
"import",
"@typescript-eslint",
"jsdoc",
"react",
"jsx-a11y",
"react-hooks",
"simple-import-sort",
"unicorn",
],
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
rules: {
// //////// //
// Disabled //
// //////// //
/** Handled by prettier */
"comma-dangle": 0,
"operator-linebreak": 0,
"implicit-arrow-linebreak": 0,
"@typescript-eslint/indent": 0,
"object-curly-newline": 0,
"template-curly-spacing": 0,
"newline-per-chained-call": 0,
"generator-star-spacing": 0,
"computed-property-spacing": 0,
"space-before-function-paren": 0,
indent: 0,
"function-paren-newline": 0,
"no-confusing-arrow": 0,
"no-multi-spaces": 0,
"object-property-newline": 0,
"brace-style": 0,
"no-nested-ternary": 0,
/** handled by no-restricted-syntax */
"guard-for-in": 0,
/**
* Use types instead of interfaces
*/
"@typescript-eslint/prefer-interface": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/no-empty-interface": 0,
/** Use import lint rules */
"@typescript-eslint/no-var-requires": 0,
/** No types required in some places, because of typescript */
"jsdoc/require-param-type": 0,
"jsdoc/require-returns-type": 0,
"react/prop-types": 0,
"react/jsx-sort-props": 0,
"react/require-default-props": 0,
/** Because of @typescript-eslint, we don't need these */
"no-use-before-define": 0,
"no-shadow": 0,
camelcase: 0,
"no-var-requires": 0,
"no-inferrable-types": 0,
"unicorn/explicit-length-check": "error",
/** Disabled react rules */
"react/jsx-one-expression-per-line": 0,
"jsx-a11y/heading-has-content": 0,
/**
* TS allows for public syntax in constructor to make a constructor
* parameter assigned to the class instance. We use this often and so
* the constructor is often empty
*/
"no-useless-constructor": 0,
/** Bad import rules, ignore them */
"import/no-named-as-default": 0,
"import/extensions": 0,
"import/prefer-default-export": 0,
// ///// //
// Rules //
// ///// //
/** Use === instead of == */
eqeqeq: ["error"],
/**
* Require class methods to call this
*/
"class-methods-use-this": ["error"],
/**
* @typescript-eslint rules
*/
"@typescript-eslint/unified-signatures": ["error"],
"@typescript-eslint/adjacent-overload-signatures": ["error"],
"@typescript-eslint/explicit-function-return-type": [
"error",
{ allowExpressions: true },
],
"@typescript-eslint/explicit-module-boundary-types": 0,
/** JSdoc Validation */
"jsdoc/require-jsdoc": ["error", JSDOC_RULES],
"jsdoc/check-types": ["error"],
"jsdoc/check-param-names": ["error", { checkDestructured: false }],
"jsdoc/require-returns": ["error"],
"jsdoc/no-types": ["error"],
"jsdoc/require-param": ["error", { checkDestructured: false }],
"jsdoc/require-param-description": ["error"],
"jsdoc/require-returns-description": ["error"],
"jsdoc/require-hyphen-before-param-description": ["error"],
"jsdoc/require-description": [
"error",
{
contexts: JSDOC_RULES.contexts.map(
(context) => context.context || context
),
},
],
/** Import validation */
"import/imports-first": ["error"],
"import/newline-after-import": ["error"],
"import/no-dynamic-require": ["error"],
"import/no-unresolved": ["error"],
"import/no-webpack-loader-syntax": ["error"],
/**
* No console logs anywhere. They are bad and should only be used for debugging.
*/
"no-console": ["error"],
/** Use template strings for concatenation */
"prefer-template": ["error"],
/**
* Limits on file size and line length, for readability
*/
"max-len": ["error", 150, { comments: 150 }],
/** Require curly brackets around newlines */
curly: ["error"],
/** Enforce consistent JSX quotes */
"jsx-quotes": ["error", "prefer-double"],
/** Accessibility on frontend react components */
"jsx-a11y/aria-props": ["error"],
"jsx-a11y/label-has-for": [
"error",
{
required: {
some: ["nesting", "id"],
},
},
],
"jsx-a11y/mouse-events-have-key-events": ["error"],
"jsx-a11y/role-has-required-aria-props": ["error"],
"jsx-a11y/role-supports-aria-props": ["error"],
/** React JSX Rules */
"react/jsx-filename-extension": [
"error",
{ extensions: [".js", ".jsx", "tsx"] },
],
"react/jsx-first-prop-new-line": ["error", "multiline"],
"react/jsx-boolean-value": ["error"],
"react/jsx-no-target-blank": ["error"],
"react/self-closing-comp": ["error"],
"react/jsx-curly-brace-presence": ["error", { props: "never" }],
/** Enforce hook rules */
"react-hooks/rules-of-hooks": ["error"],
/** Test for dangerously set HTML */
"react/no-danger": ["error"],
/** Ensure eslint-disable is not present when its not disabling any rule */
"eslint-comments/no-unused-disable": ["error"],
/** Arrow functions should have parentheses around inputs */
"arrow-parens": ["error", "always"],
"arrow-body-style": ["error", "as-needed"],
/** Max lines in a file */
"max-lines": ["error", 350],
/** Generator functions should call `yield` */
"require-yield": ["error"],
/** Prefer for-of to for loop (in general we prefer map/forEach over for of as well) */
"@typescript-eslint/prefer-for-of": ["error"],
/** Should not alias this to another command */
"@typescript-eslint/no-this-alias": ["error"],
/** Prevent use of global variables */
"no-restricted-globals": ["error"],
/** No unnecessary async statements on a function */
"require-await": ["error"],
/**
* If there are more than 4 arguments in a function, it should be refactored
* to have fewer arguments. The easiest way of doing this is to create an
* "options" parameter that holds all of the missing parameters
*
* @see https://eslint.org/docs/rules/max-params
*/
"max-params": ["error", 4],
/**
* Sort imports
*
* @see https://github.com/lydell/eslint-plugin-simple-import-sort
*/
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
// No unused imports or variables. Convenient for pre-commit hook.
"@typescript-eslint/no-unused-vars": 2,
// //////// //
// Warnings //
// //////// //
/** We want to eventually turn this to an error */
"@typescript-eslint/ban-types": ["warn"],
/** Accessibility rules */
"jsx-a11y/media-has-caption": ["warn"],
"jsx-a11y/click-events-have-key-events": ["warn"],
"jsx-a11y/no-static-element-interactions": ["warn"],
/** We disagree with these rules that are configured by eslint-config-preact */
"constructor-super": "off",
"no-redeclare": "off",
"no-duplicate-imports": "off",
"no-undef": "off",
"no-dupe-class-members": "off",
"no-unused-vars": "off", // we already have this covered by typescript-eslint config
"no-empty": ["error"],
"no-empty-pattern": ["error"],
"react/no-direct-mutation-state": ["error"],
"react/display-name": "off",
},
overrides: [
// ///////// //
// overrides //
// ///////// //
/**
* Hooks modify their local parameters often, and so param
* reassignments are allowed. Also the jsdoc comments are not
* needed.
*/
{
files: ["**/hooks.ts"],
rules: {
"no-param-reassign": 0,
"jsdoc/require-param": 0,
},
},
/**
* Javascript files can ignore type requirements as we typically want to
* migrate these js files to typescript at some point.
*/
{
files: ["*.js"],
rules: {
"jsdoc/no-types": 0,
"@typescript-eslint/explicit-function-return-type": 0,
},
},
/**
* TSX files are all props and state so jsdoc
* params and returns are often redundant
*/
{
files: ["**/*.tsx"],
rules: {
"jsdoc/require-returns": 0,
"jsdoc/require-param": 0,
"no-empty-pattern": 0,
},
},
/**
* These are react components but the props types are defined explicitly
* and so the extra comment is almost always redundant
*/
{
files: ["**/wrappers.ts"],
rules: {
"jsdoc/require-param": 0,
"jsdoc/require-returns": 0,
"no-empty-pattern": 0,
},
},
{
files: ["*.ts"],
rules: {
"simple-import-sort/imports": [
"error",
{
groups: [
// Side effect imports.
["^\\u0000"],
// Anything not matched in another group.
["^"],
// @main imports.
["^@main/"],
// Relative imports.
["^\\."],
],
},
],
},
},
],
settings: {
/** React settings based on version in monorepo */
react: {
version: "detect",
},
/** Allow typescript alias resolution */
"import/resolver": {
typescript: {},
},
},
};
/* eslint-enable max-lines */