-
Notifications
You must be signed in to change notification settings - Fork 1
/
eslint.js
407 lines (402 loc) · 11.1 KB
/
eslint.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
/*
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
https://github.com/typescript-eslint/tslint-to-eslint-config
It represents the closest reasonable ESLint configuration to this
project's original TSLint configuration.
We recommend eventually switching this configuration to extend from
the recommended rulesets in typescript-eslint.
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
Happy linting! 💖
*/
module.exports = {
env: {
es6: true,
},
extends: [
/**
* Turns off all rules that are unnecessary or might conflict with Prettier.
*/
'prettier',
/**
* Adds React-related rules.
*/
'plugin:react/recommended',
/**
* Adds React hooks-related rules.
*/
'plugin:react-hooks/recommended',
],
/**
* An ESLint parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
*/
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
plugins: ['@typescript-eslint', 'import', 'jsdoc', '@babel'],
rules: {
/**
* Require that member overloads be consecutive
*/
'@typescript-eslint/adjacent-overload-signatures': 'error',
/**
* Disallows awaiting a value that is not a Thenable
*/
'@typescript-eslint/await-thenable': 'error',
/**
* Bans specific types from being used
*/
'@typescript-eslint/ban-types': [
'error',
{
extendDefaults: true,
types: {
Boolean: 'Avoid using the `Boolean` type. Did you mean `boolean`?',
Symbol: 'Avoid using the `Boolean` type. Did you mean `symbol`?',
Number: 'Avoid using the `Number` type. Did you mean `number`?',
String: 'Avoid using the `String` type. Did you mean `string`?',
Object: 'Avoid using the `Object` type. Did you mean `object`?',
Function:
'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
/*
* Allow use of '{}' - we use it to define React components with no properties
*/
'{}': false,
},
},
],
/**
* Enforces consistent usage of type assertions
*/
'@typescript-eslint/consistent-type-assertions': ['error', {assertionStyle: 'as'}],
/**
* Enforce dot notation whenever possible
*/
'@typescript-eslint/dot-notation': 'error',
/**
* Disallow empty functions
*/
'@typescript-eslint/no-empty-function': 'error',
/**
* Forbids the use of classes as namespaces
*/
'@typescript-eslint/no-extraneous-class': 'error',
/**
* Requires Promise-like values to be handled appropriately
*/
'@typescript-eslint/no-floating-promises': 'error',
/**
* Disallow iterating over an array with a for-in loop
*/
'@typescript-eslint/no-for-in-array': 'error',
/**
* Enforce valid definition of `new` and `constructor`
*/
'@typescript-eslint/no-misused-new': 'error',
/**
* Disallow the use of parameter properties in class constructors
*/
'@typescript-eslint/parameter-properties': 'error',
/**
* Disallow aliasing this
*/
'@typescript-eslint/no-this-alias': 'error',
/**
* Warns if a type assertion does not change the type of an expression
*/
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
/**
* Disallow unused expressions
*/
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
},
],
/**
* Prefer a `for-of` loop over a standard `for` loop if the index is only used to access the array being iterated
*/
'@typescript-eslint/prefer-for-of': 'error',
/**
* Use function types instead of interfaces with call signatures
*/
'@typescript-eslint/prefer-function-type': 'error',
/**
* Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules
*/
'@typescript-eslint/prefer-namespace-keyword': 'error',
/**
* Requires that private members are marked as `readonly` if they're never modified outside of the constructor
*/
'@typescript-eslint/prefer-readonly': 'error',
/**
* Requires any function or method that returns a Promise to be marked async
*/
'@typescript-eslint/promise-function-async': 'error',
/**
* When adding two variables, operands must both be of type number or of type string
*/
'@typescript-eslint/restrict-plus-operands': 'error',
/**
* Sets preference level for triple slash directives versus ES6-style import declarations
*/
'@typescript-eslint/triple-slash-reference': [
'error',
{
path: 'always',
types: 'prefer-import',
lib: 'always',
},
],
/**
* Enforces unbound methods are called with their expected scope
*/
'@typescript-eslint/unbound-method': 'error',
/**
* Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter
*/
'@typescript-eslint/unified-signatures': 'error',
/**
* Prevents conditionals where the type is always truthy or always falsy
*/
'@typescript-eslint/no-unnecessary-condition': 'off',
/**
* Checks for redeclaration of entities with the same name
*/
'@typescript-eslint/no-redeclare': 'off',
/**
*
*/
'prefer-arrow-callback': ['error', {allowNamedFunctions: true}],
/**
* Ensures `super()` is called in derived class constructors
*/
'constructor-super': 'error',
/**
* Require === and !==
*/
eqeqeq: ['error', 'smart'],
/**
* Blacklist certain identifiers to prevent them being used
* "There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
*/
'id-blacklist': [
'error',
'any',
'Number',
'number',
'String',
'string',
'Boolean',
'boolean',
'Undefined',
'undefined',
],
/**
* Require identifiers to match a specified regular expression
*/
'id-match': 'error',
/**
* Report imported names marked with @deprecated documentation tag
*/
'import/no-deprecated': 'error',
/**
* Forbid the use of extraneous packages
*/
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/__tests__/**/*', '**/__story__/**/*', '**/fixtures/**/*'],
optionalDependencies: false,
},
],
/**
* Reports invalid alignment of JSDoc block asterisks.
*/
'jsdoc/check-alignment': 'error',
/**
* Reports invalid padding inside JSDoc blocks.
*/
'jsdoc/check-indentation': 'error',
/**
* This rule reports types being used on @param or @returns.
*/
'jsdoc/no-types': 'error',
/**
* The use of bitwise operators in JavaScript is very rare and often & or | is simply a mistyped && or ||, which will lead to unexpected behavior.
*/
'no-bitwise': 'error',
/**
* Disallow assignment operators in conditional statements
*/
'no-cond-assign': 'error',
/**
* Disallow console.log
*/
'no-console': [
'error',
{
allow: [
'debug',
'info',
'dirxml',
'warn',
'error',
'time',
'timeEnd',
'timeLog',
'trace',
'assert',
'clear',
'count',
'countReset',
'group',
'groupCollapsed',
'groupEnd',
'table',
'Console',
'markTimeline',
'profile',
'profileEnd',
'timeline',
'timelineEnd',
'timeStamp',
'context',
],
},
],
/**
* Disallow the use of debugger
*/
'no-debugger': 'error',
/**
* Rule to disallow a duplicate case label
*/
'no-duplicate-case': 'error',
/**
* Disallow duplicate imports
*/
'no-duplicate-imports': 'error',
/**
* Disallow empty destructuring patterns
*/
'no-empty': 'error',
/**
* Disallow eval()
*/
'no-eval': 'error',
/**
* Disallow Case Statement Fallthrough
*/
'no-fallthrough': 'error',
/**
* Disallow this keywords outside of classes or class-like objects.
*
* We use class fields in our class components, which is an ES proposal.
* Eslint generates false positives for no-invalid-this in this case -
* we need to use the babel plugin, which checks them correctly.
*/
'no-invalid-this': 'off',
'@babel/no-invalid-this': 'error',
/**
* Disallow Primitive Wrapper Instances
*/
'no-new-wrappers': 'error',
/**
* Disallow variable redeclaration
*/
'no-redeclare': 'off',
/**
* Disallow var declaration
*/
'no-var': 'off',
/**
* Disallow specific imports
*/
'no-restricted-imports': [
'error',
'lodash',
'date-fns',
'@material-ui/core',
'@material-ui/styles',
'@material-ui/icons',
],
/**
* Disallow Use of the Comma Operator
*/
'no-sequences': 'error',
/**
* Disallow Shadowing of Restricted Names
*/
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
/**
* Disallow sparse arrays
*/
'no-sparse-arrays': 'error',
/**
* Disallow template literal placeholder syntax in regular strings
*/
'no-template-curly-in-string': 'error',
/**
* Disallow Initializing to undefined
*/
'no-undef-init': 'error',
/**
* Disallow control flow statements in finally blocks
*/
'no-unsafe-finally': 'error',
/**
* Require let or const instead of var
*/
'no-var': 'error',
/**
* Enforce variables to be declared either separately in functions
*/
'one-var': ['error', 'never'],
/**
* Suggest using of const declaration for variables that are never modified after declared
*/
'prefer-const': 'error',
/**
* Require Radix Parameter
*/
radix: 'error',
/**
* Require calls to isNaN() when checking for NaN
*/
'use-isnan': 'error',
// React-specific rule overrides
/**
* We use TypeScript - we don't use dynamic prop type checks
*/
'react/prop-types': 'off',
/**
* We use anonymous functions for components - having displayNames would be good,
* but we don't want to change the entire code base
*/
'react/display-name': 'off',
/**
* Enable ' in unescaped entities - it's safe and escaping it makes adding copy harder
*/
'react/no-unescaped-entities': [
'error',
{
forbid: ['>', '}', '"'],
},
],
/**
* Make exhaustive deps mandatory
*/
'react-hooks/exhaustive-deps': 'error',
/**
* Ignore `css` property on components
*/
'react/no-unknown-property': ['error', {ignore: ['css']}],
},
};