-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.eslintrc.json
327 lines (296 loc) · 10.1 KB
/
.eslintrc.json
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
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"allowImportExportEverywhere": false,
"tsconfigRootDir": ".",
"project": "./tsconfig.json"
},
"plugins": [
"filenames",
"meteor",
"@typescript-eslint",
"deprecation",
"jolly-roger"
],
"reportUnusedDisableDirectives": true,
"extends": [
"airbnb",
"plugin:meteor/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:react-hooks/recommended",
"plugin:eslint-comments/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
// Make sure to put this last so it can override any other rules
"prettier"
],
"settings": {
"import/resolver": {
"meteor": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
},
"typescript": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"rules": {
// explicit returns can sometimes be more readable and avoid the issue of "I want to return an
// object literal but ES6 interprets it as a function body with a void expression"
"arrow-body-style": "off",
// Publish functions don't really need to be named.
"func-names": "off",
// For Match expressions
"new-cap": [
"error",
{
"capIsNewExceptions": [
"Optional",
"OneOf",
"Maybe",
"ObjectIncluding",
"Router"
]
}
],
// sometimes else after a return reads more clearly
"no-else-return": "off",
// same for continue
"no-continue": "off",
// We sometimes use these in various forms
"no-underscore-dangle": [
"error",
{
"allow": [
"_id",
"_this",
"_dropIndex",
"_redirectUri",
"_postRequest",
"_anyMethodsAreOutstanding",
"_schemaKeys",
"_schema",
"_retrieveCredentialSecret",
"_loginStyle",
"_stateParam",
"_name",
"_allSubscriptionsReady",
"_onMigrate",
"_def",
"_makeNewID"
]
}
],
"camelcase": [
"error",
{
"properties": "never",
"allow": [
"__meteor_runtime_config__",
// attempt to capture versioned Google APIs
"[a-z]+_v[0-9]+"
]
}
],
"no-constant-condition": ["error", { "checkLoops": false }],
// We have files with multiple React components. Maybe we should split them out
// later, but right now I don't want to deal with this
"react/no-multi-comp": "off",
"max-classes-per-file": "off",
// Absolute imports work with Meteor, but aren't well-understood by IDEs, like VS Code
"import/no-absolute-path": "error",
// We don't use imports with extensions
"import/extensions": ["error", "never"],
// Allow optional imports
"import/no-extraneous-dependencies": [
"error",
{
"optionalDependencies": true,
"devDependencies": ["tests/**"]
}
],
// Imports should be grouped, and sorted within the group. Meteor imports
// are their own group, after built-ins and before other external libraries
"import/order": [
"error",
{
"alphabetize": { "order": "asc" },
"pathGroups": [
{
"pattern": "meteor/**",
"group": "external",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": ["builtin"],
"newlines-between": "never"
}
],
// Require type-only imports as appropriate - this reduces the size of our
// runtime bundle
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports"
}
],
// Files with default exports should be named to match them
"filenames/match-exported": "error",
// This is complaining a lot and I don't really want to write dozens of lines of
// default prop values of `undefined`
"react/require-default-props": "off",
// This seems to interact poorly with HOCs like forwardRef. TypeScript means
// that we don't really have to worry about missing types on our component
// props
"react/prop-types": "off",
// We use spread props a lot for HOCs or other wrapper-type components
"react/jsx-props-no-spreading": "off",
// We have methods on classes that don't use this, but still need to be an
// instance method instead of a class method (e.g. because they're
// implementing a subset of some larger interface). There's no way to
// satisfy this linter without breaking those interfaces.
"class-methods-use-this": "off",
// Allow tsx files
"react/jsx-filename-extension": [1, { "extensions": [".jsx", ".tsx"] }],
// Detect missing deps for non-standard hooks
"react-hooks/exhaustive-deps": [
"warn",
{ "additionalHooks": "useTracker|useFind" }
],
// Allow disabling eslint rules on more than a single line, but only across a whole file
"eslint-comments/disable-enable-pair": [
"error",
{ "allowWholeFile": true }
],
// Allow void statements to explicitly tag when we're throwing away a promise
"no-void": ["error", { "allowAsStatement": true }],
// Relax typescript checks to accommodate existing code
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
],
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
// Enable a subset of strict rules that are useful
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-base-to-string": "error",
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/non-nullable-type-assertion-style": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-return-this-type": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
// Enforce safety around promises
"no-return-await": "off",
"@typescript-eslint/return-await": "error",
// There's some risk that this causes us to write parallelizable code that
// runs in serial, but so far most of the cases where we hit this, we need
// to run serially, either so we avoid overwhelming a rate limit or because
// we're paginating over results
"no-await-in-loop": "off",
// Show errors for deprecated code
"deprecation/deprecation": "error",
// Override Airbnb's style guide to allow "for-of" iteration, which is
// already supported by Meteor
"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."
}
],
// Some external libraries (e.g. Bugsnag) require modifying parameter props
// as part of their interface
"no-param-reassign": ["error", { "props": false }],
"jolly-roger/no-disallowed-sync-methods": ["error"],
// Match existing style
"prefer-destructuring": "off",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"react/function-component-definition": [
"error",
{
"namedComponents": "arrow-function"
}
],
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/media-has-caption": "off"
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
// The Javascript versions of these rules don't handle TypeScript
// scoping correctly, so use the TypeScript-specific ones instead
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
}
},
{
"files": "**/client/**",
"env": {
"browser": true
},
"rules": {
"jolly-roger/no-disallowed-sync-methods": "off"
}
},
{
"files": "eslint/**",
"parserOptions": { "project": "eslint/tsconfig.json" }
},
{
"files": "**/server/**",
"env": {
"node": true
}
},
{
"files": "types/**",
"rules": {
// type declarations for other libraries don't get to choose their
// export structure
"import/prefer-default-export": "off",
// or their variable names
"no-underscore-dangle": "off",
// we often need to declare unused variables when extending generic
// types
"@typescript-eslint/no-unused-vars": "off"
}
},
{
"files": "tests/**",
"rules": {
// arrow functions with mocha are discouraged
"func-names": "off",
"prefer-arrow-callback": "off",
// since tests run in both client and server context, sometimes we need
// conditional imports, which can only be easily done with require
"global-require": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/consistent-type-imports": "off"
}
}
]
}