forked from measuredco/dnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
288 lines (277 loc) · 8.85 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
module.exports = {
extends: ['airbnb', 'prettier', 'plugin:prettier/recommended'],
plugins: ['prettier', '@emotion', 'react', 'react-hooks', 'import', 'es5'],
parser: '@babel/eslint-parser',
env: {
es6: true,
browser: true,
node: true,
},
globals: {
TimeoutID: true,
IntervalID: true,
AnimationFrameID: true,
},
rules: {
// Error on prettier violations
'prettier/prettier': 'error',
// New eslint style rules that is not disabled by prettier:
'lines-between-class-members': 'off',
// Allowing warning and error console logging
// use `invariant` and `warning`
'no-console': ['error'],
// Opting out of prefer destructuring
'prefer-destructuring': 'off',
// Disallowing the use of variables starting with `_` unless it called on `this`.
// Allowed: `this._secret = Symbol()`
// Not allowed: `const _secret = Symbol()`
'no-underscore-dangle': [
'error',
{
allowAfterThis: true,
},
],
// Cannot reassign function parameters but allowing modification
'no-param-reassign': [
'error',
{
props: false,
},
],
// Named exports are kewl
'import/prefer-default-export': 'off',
// Don't tell me what to do!
'max-classes-per-file': 'off',
// Allowing ++ on numbers
'no-plusplus': 'off',
// Always enforcing the use of curly braces for if statements
curly: ['error', 'all'],
'no-restricted-syntax': [
// Nicer booleans #1
// Disabling the use of !! to cast to boolean
'error',
{
selector:
'UnaryExpression[operator="!"] > UnaryExpression[operator="!"]',
message:
'!! to cast to boolean relies on a double negative. Use Boolean() instead',
},
// Nicer booleans #2
// Avoiding accidental `new Boolean()` calls
// (also covered by `no-new-wrappers` but i am having fun)
{
selector: 'NewExpression[callee.name="Boolean"]',
message:
'Avoid using constructor: `new Boolean(value)` as it creates a Boolean object. Did you mean `Boolean(value)`?',
},
// We are using a useLayoutEffect / useEffect switch to avoid SSR warnings for useLayoutEffect
// We want to ensure we use `import useEffect from '*use-isomorphic-layout-effect'`
// to ensure we still get the benefits of `eslint-plugin-react-hooks`
{
selector:
'ImportDeclaration[source.value=/use-isomorphic-layout-effect/] > ImportDefaultSpecifier[local.name!="useLayoutEffect"]',
message:
'Must use `useLayoutEffect` as the name of the import from `*use-isomorphic-layout-effect` to leverage `eslint-plugin-react-hooks`',
},
// No usage of `tiny-invariant`. Must use our own invariant for error flow
{
selector: 'ImportDeclaration[source.value="tiny-invariant"]',
message:
'Please use our own invariant function (src/invariant.js) to ensure correct error flow',
},
// Must use invariant to throw
{
selector: 'ThrowStatement',
message:
'Please use invariant (src/invariant.js) for throwing. This is to ensure correct error flows',
},
],
// https://github.com/airbnb/javascript/issues/2500
'no-restricted-exports': [
'error',
{
restrictedNamedExports: ['then'],
},
],
// Allowing Math.pow rather than forcing `**`
'no-restricted-properties': [
'off',
{
object: 'Math',
property: 'pow',
},
],
'no-restricted-imports': [
'error',
{
paths: [
// Forcing use of useMemoOne
{
name: 'react',
importNames: ['useMemo', 'useCallback'],
message:
'`useMemo` and `useCallback` are subject to cache busting. Please use `useMemoOne`',
},
// Forcing use aliased imports from useMemoOne
{
name: 'use-memo-one',
importNames: ['useMemoOne', 'useCallbackOne'],
message:
'use-memo-one exports `useMemo` and `useCallback` which work nicer with `eslint-plugin-react-hooks`',
},
// Disabling using of useLayoutEffect from react
{
name: 'react',
importNames: ['useLayoutEffect'],
message:
'`useLayoutEffect` causes a warning in SSR. Use `useIsomorphicLayoutEffect`',
},
],
},
],
'react/function-component-definition': [
'error',
{
namedComponents: ['arrow-function', 'function-declaration'],
},
],
// Allowing jsx in files with any file extension (old components have jsx but not the extension)
'react/jsx-filename-extension': 'off',
// Not requiring default prop declarations all the time
'react/require-default-props': 'off',
// Opt out of preferring stateless functions
'react/prefer-stateless-function': 'off',
// Allowing files to have multiple components in it
'react/no-multi-comp': 'off',
// Sometimes we use the PropTypes.object PropType for simplicity
'react/forbid-prop-types': 'off',
// Allowing the non function setState approach
'react/no-access-state-in-setstate': 'off',
// Causes error suggesting we replace `hydrate` with `hydrateRoot`, which would break tests with React 16 and 17
'react/no-deprecated': 'off',
// Opting out of this
'react/destructuring-assignment': 'off',
// Adding 'skipShapeProps' as the rule has issues with correctly handling PropTypes.shape
'react/no-unused-prop-types': [
'error',
{
skipShapeProps: true,
},
],
// Having issues with this rule not working correctly
'react/default-props-match-prop-types': 'off',
// We do not need PropTypes validation
'react/prop-types': 'off',
// Allowing functions to be passed as props
'react/jsx-no-bind': 'off',
// Allowing importing from dev deps (for stories and tests)
'import/no-extraneous-dependencies': 'off',
// Enforce rules of hooks
'react-hooks/rules-of-hooks': 'error',
// Second argument to hook functions
'react-hooks/exhaustive-deps': 'error',
'react/jsx-props-no-spreading': 'off',
// using <React.Fragment> is fine
'react/jsx-fragments': 'off',
// all good to declare static class members in the class
'react/static-property-placement': 'off',
// don't need to initialize state in a constructor
'react/state-in-constructor': 'off',
},
overrides: [
// Forbid using not es5 methods
{
files: 'src/**/*.js',
rules: {
'es5/no-es6-methods': 'error',
'es5/no-es6-static-methods': [
'error',
{
exceptMethods: ['Object.assign'],
},
],
},
},
// NodeJS files
{
extends: ['plugin:node/recommended'],
files: [
'**/*.eslintrc.js',
'.stylelintrc.js',
'a11y-audit-parse.js',
'browser-test-harness.js',
'babel.config.js',
'commitlint.config.js',
'jest.config.js',
'lighthouse.config.js',
'rollup.config.js',
'server-ports.js',
'test/**/*.js?(x)',
],
},
{
extends: ['plugin:node/recommended-module'],
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
browser: false,
es6: false,
},
files: ['rollup.config.js'],
rules: {
'node/no-unsupported-features/es-syntax': [
'error',
{
ignores: ['modules'],
},
],
},
},
// Typescript files
{
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier',
],
settings: {
'import/resolver': {
typescript: {
project: ['./tsconfig.json', './*/tsconfig.json'],
},
},
},
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
files: ['**/*.ts?(x)'],
rules: {
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/consistent-type-definitions': [
'error',
'interface',
],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': ['error'],
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': ['error'],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
},
},
],
};