-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy path.eslintrc.js
More file actions
241 lines (221 loc) · 6.96 KB
/
.eslintrc.js
File metadata and controls
241 lines (221 loc) · 6.96 KB
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
var path = require('path');
module.exports = {
root: true,
settings: {
'import/core-modules': ['electron'],
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
react: {
version: 'detect',
},
'import/resolver': {
node: {
paths: [path.resolve(__dirname)],
},
},
},
extends: [
'airbnb-base',
'prettier',
'plugin:@typescript-eslint/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
plugins: ['mocha', 'more', '@typescript-eslint', 'local-rules'],
parser: '@typescript-eslint/parser',
parserOptions: { project: ['tsconfig.json'] },
rules: {
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
},
],
// Enforce curlies always
curly: ['error', 'all'],
'brace-style': ['error', '1tbs'],
// prevents us from accidentally checking in exclusive tests (`.only`):
'mocha/no-exclusive-tests': 'error',
// encourage consistent use of `async` / `await` instead of `then`
'more/no-then': 'error',
// it helps readability to put public API at top,
'no-use-before-define': 'off',
// useful for unused or internal fields
'no-underscore-dangle': 'off',
// though we have a logger, we still remap console to log to disk
'no-console': 'error',
// consistently place operators at end of line except ternaries
'operator-linebreak': 'error',
// Use LF to stay consistent
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/no-misused-promises': 'error',
// make imports without file extensions
'import/extensions': ['warn', 'never'],
// NOTE Comment out this line when debugging cyclic dependencies / circular imports
'import/no-cycle': 'off',
// Prettier overrides:
'arrow-parens': 'off',
'no-nested-ternary': 'off',
'function-paren-newline': 'off',
'import/prefer-default-export': 'off',
'operator-linebreak': 'off',
'prefer-destructuring': 'off',
'max-classes-per-file': 'off',
'lines-between-class-members': 'off',
'@typescript-eslint/no-explicit-any': 'off', // to reenable later
'arrow-body-style': 'off',
'no-plusplus': 'off',
'no-continue': 'off',
'no-void': 'off',
'default-param-last': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'class-methods-use-this': 'off',
camelcase: 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
// 'no-unused-expressions': 'off',
// '@typescript-eslint/no-unused-expressions': 'error',
'max-len': [
'error',
{
// Prettier generally limits line length to 80 but sometimes goes over.
// The `max-len` plugin doesn’t let us omit `code` so we set it to a
// high value as a buffer to let Prettier control the line length:
code: 999,
// We still want to limit comments as before:
comments: 200,
ignoreUrls: true,
ignoreRegExpLiterals: true,
},
],
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
// There is an issue with the current version of react-use where it requires an arbitrary 'Locale' package on the window object which causes random app crashes on startup in some cases
{
name: 'react-use',
message:
"Don't import from 'react-use' directly. Please use a default import for each hook from 'react-use/lib' instead.",
},
{
name: 'zod',
allowTypeImports: true,
message:
"Don't import from 'zod' directly. Please use a default import from 'ts/utils/zod' instead.",
},
],
},
],
'local-rules/styled-components-transient-props': [
'error',
{
additionalValidProps: ['as', 'forwardedAs', 'theme'],
ignoreComponentPatterns: ['^Motion', '^Animated'],
},
],
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
// Note: Removed ForOfStatement restriction
],
},
overrides: [
{
files: ['*_test.ts'],
rules: {
'no-unused-expressions': 'off',
'no-await-in-loop': 'off',
'no-empty': 'off',
},
},
{
files: ['ts/state/ducks/*.tsx', 'ts/state/ducks/*.ts'],
rules: { 'no-param-reassign': ['error', { props: false }] },
},
{
files: ['ts/node/**/*.ts', 'ts/test/**/*.ts'],
rules: { 'no-console': 'off', 'import/no-extraneous-dependencies': 'off' },
},
{
files: ['ts/localization/*.ts', 'ts/localization/generated/*.ts'], // anything in ts/localization has to only reference the files in that folder (this makes it reusable)
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
'a*',
'b*',
'c*',
'd*',
'e*',
'f*',
'g*',
'h*',
'i*',
'j*',
'k*',
'l*',
'm*',
'n*',
'o*',
'p*',
'q*',
'r*',
's*',
't*',
'u*',
'v*',
'w*',
'x*',
'y*',
'z*',
'0*',
'1*',
'2*',
'3*',
'4*',
'5*',
'6*',
'7*',
'8*',
'9*',
'!./*',
'!./generated/*',
], // Disallow everything except ts/localization, this is the worst,
// but regexes are broken on our eslint8, and upgrading it means
// we need to bump node, which needs to bump electron.... and having '*' makes the other rules droped..
},
],
},
},
],
};