-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.js
279 lines (222 loc) · 7.7 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
// Rules to guard against possible mistakes
const possibleErrorRules = {
// Disallow unused variables/imports
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"varsIgnorePattern": "^_",
"args": "none", // don't check function args
"ignoreRestSiblings": false, // don't check rests like { a, ...b }
}],
// Disallow using variables/functions/classes/enums/types before they're
// defined
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
// Enforce annotating function types and return types
"@typescript-eslint/explicit-function-return-type": ["error", {
// Allow no return type on function expressions
"allowExpressions": true,
// Allow function type to go on variable
"allowTypedFunctionExpressions": true,
// Functions immediately returning a function type will be ignored
"allowHigherOrderFunctions": true,
}],
// Enforce that in `foo + bar`, the variables are either both numbers or
// both strings
"@typescript-eslint/restrict-plus-operands": "error",
// Prefer `x` and `!x` over `x === true` and `x === false`
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
// Disallow truthy checks on variables that must be truthy based on their
// type
"@typescript-eslint/no-unnecessary-condition": "error",
// Prefer things like `x || y` over `x ? x : y` or `!x` over `x ? false : true`
"no-unneeded-ternary": ["error", {
"defaultAssignment": false,
}],
// Disallow calling methods without the original class scope
"@typescript-eslint/unbound-method": ["error", {
"ignoreStatic": true,
}],
// Prefer arrow lambdas over aliasing `this`
"@typescript-eslint/no-this-alias": "error",
// Prefer `const`
"prefer-const": ["warn", {
"destructuring": "all",
}],
// Don't use `var`
"no-var": "error",
// Disallow fallthrough in switches
"no-fallthrough": "error",
// Prefer `for..of` loops when index is not being used
"@typescript-eslint/prefer-for-of": "warn",
// Disallow `for..in` loops when iterating over arrays
"@typescript-eslint/no-for-in-array": "error",
// Disallow explicit Array constructor calls without a type parameter
"@typescript-eslint/no-array-constructor": "error",
// Disallow `interface Foo {}`
"@typescript-eslint/no-empty-interface": ["error", {
"allowSingleExtends": true,
}],
// Enforce proper new/constructor usage
"@typescript-eslint/no-misused-new": "error",
// Discourage using classes as namespaces
"@typescript-eslint/no-extraneous-class": "error",
// Disallow silent duplicate class members
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
// Prefer `() => Foo` over `interface Foo { (): Bar; }`
"@typescript-eslint/prefer-function-type": "error",
// Disallow extra non-null assertions
"@typescript-eslint/no-extra-non-null-assertion": "warn",
// Disallow type assertion that does not change the type of an expression
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
// Enforce proper handling of Promises
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
// Enforce functions returning Promises to be marked async
"@typescript-eslint/promise-function-async": "error",
// Ensure that switches on union types are exhaustive
"@typescript-eslint/switch-exhaustiveness-check": "error",
// Enforce that optional or default parameters come last
"@typescript-eslint/default-param-last": "error",
// Disallow comparing to NaN, prefer `Number.isNaN()`
"use-isnan": "error",
};
// Rules that enforce consistent code style
const styleRules = {
"max-len": ["warn", 120],
// Indent with 4 spaces
"indent": "off",
"@typescript-eslint/indent": ["warn", 4, {
"ignoredNodes": [
"TemplateLiteral > *",
"TSTypeReference > TSTypeParameterInstantiation",
],
}],
// Disallow trailing whitespace
"no-trailing-spaces": "warn",
// Prefer the one true brace style
"brace-style": "off",
"@typescript-eslint/brace-style": ["warn", "1tbs", {
"allowSingleLine": true,
}],
// Prefer `if (...) { ... } over if (...) ...`
"curly": "warn",
// Prefer using `===` over `==`
"eqeqeq": "warn",
// Prefer `{ ... }` over `{...}`
"object-curly-spacing": ["warn", "always"],
// Prefer `{ ... }` over `{...}` for blocks
"block-spacing": ["warn", "always"],
// Prefer `[...]` over `[ ... ]`
"array-bracket-spacing": ["warn", "never"],
// Always prefer a semicolon
"semi": "off",
"@typescript-eslint/semi": ["warn", "always"],
// Disallow redundant semicolons
"no-extra-semi": "off",
"@typescript-eslint/no-extra-semi": "warn",
// Disallow space before semicolon
"semi-spacing": "warn",
// Enforce consistent spacing around commas
"comma-spacing": "off",
"@typescript-eslint/comma-spacing": "warn",
// Prefer commas on the end of lines
"comma-style": "warn",
// Disallow unnecessary spaces
"no-multi-spaces": "warn",
// Prefer `foo + bar` over `foo+bar`
"space-infix-ops": "warn",
// Prefer double-quoted strings
"quotes": "off",
"@typescript-eslint/quotes": ["warn", "double", {
"allowTemplateLiterals": true,
"avoidEscape": true,
}],
// Prefer `// foo` over `//foo`
"spaced-comment": ["warn", "always", {
"line": {
"markers": ["/"],
},
"block": {
"balanced": true,
},
}],
// Prefer `function foo() { ... }` over `function foo () { ... }`
// Prefer `function() { ... }` over `function () { ... }`
"space-before-function-paren": "off",
"@typescript-eslint/space-before-function-paren": ["warn", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
// Prefer "if (" over "if("
"keyword-spacing": "warn",
// Prefer `foo(args)` over `foo (args)`
"func-call-spacing": "off",
"@typescript-eslint/func-call-spacing": "warn",
// Prefer `(...) {` over `(...){`
"space-before-blocks": ["warn", "always"],
// Prefer `let x: string` over `let x:string`
"@typescript-eslint/type-annotation-spacing": "warn",
// Prefer `T[]` and `readonly T[]` over `Array<T>` and `ReadonlyArray<T>`
"@typescript-eslint/array-type": ["warn", {
"default": "array",
"readonly": "array",
}],
// Prefer `x as foo` over `<foo> x`
"@typescript-eslint/consistent-type-assertions": ["warn", {
"assertionStyle": "as",
"objectLiteralTypeAssertions": "allow-as-parameter",
}],
// Prefer `{ a: foo; b: bar; }` over `{ a: foo, b: bar }`
// Prefer `{ a: foo; b: bar; }` over `{ a: foo; b: bar }`
"@typescript-eslint/member-delimiter-style": ["warn", {
"multiline": {
"delimiter": "semi",
"requireLast": true,
},
"singleline": {
"delimiter": "semi",
"requireLast": true,
},
}],
// Prefer assignments like `let foo: 2 as const` over `let foo: 2 = 2`
"@typescript-eslint/prefer-as-const": "warn",
// Prefer Array.prototype.includes over Array.prototype.indexOf for
// inclusion checks
"@typescript-eslint/prefer-includes": "warn",
// Prefer object spreads to `Object.assign()`
"prefer-object-spread": "warn",
};
const disabledRules = {
"no-inner-declarations": "off",
};
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json",
},
"plugins": [
"@typescript-eslint"
],
"rules": {
...possibleErrorRules,
...styleRules,
...disabledRules,
},
};