forked from MallowTech/react-beautiful-dnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
239 lines (206 loc) · 7.07 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
module.exports = {
extends: [
'prettier',
'airbnb',
'plugin:flowtype/recommended',
'prettier/react',
'prettier/flowtype',
'plugin:jest/recommended',
'plugin:prettier/recommended',
],
parser: 'babel-eslint',
plugins: [
'prettier',
'flowtype',
'emotion',
'react',
'react-hooks',
'import',
'jest',
'es5',
],
env: {
es6: true,
browser: true,
node: true,
'jest/globals': true,
},
globals: {
// flow 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 (nicer with flow in lots of cases)
'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 Array.from as it pulls in a large amount of babel helpers
{
selector: 'MemberExpression[object.name="Array"][property.name="from"]',
message:
'Not allowing using of Array.from to save kbs. Please use native-with-fallback/from',
},
// 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',
},
],
// 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`',
},
],
},
],
// 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',
// 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',
// Allowing functions to be passed as props
'react/jsx-no-bind': 'off',
// Require // @flow at the top of files
'flowtype/require-valid-file-annotation': [
'error',
'always',
{ annotationStyle: 'line' },
],
// 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',
'jest/expect-expect': [
'error',
{
assertFunctionNames: [
'expect',
// these functions will run expect internally
'withWarn',
'withError',
'withoutError',
'withoutWarn',
],
},
],
},
overrides: [
// Forbid using not es5 methods
{
files: 'src/**/*.js',
rules: {
'es5/no-es6-methods': 'error',
'es5/no-es6-static-methods': [
'error',
{ exceptMethods: ['Object.assign'] },
],
},
},
],
};