-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
280 lines (248 loc) · 8.14 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
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module', // Allows for the use of imports
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
plugins: ['@typescript-eslint', 'eslint-comments', 'import', 'react-hooks', 'unused-imports'],
extends: [
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
'plugin:react/recommended',
],
env: {
node: true,
browser: true,
jest: true,
},
settings: {
react: {
version: 'detect',
},
'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
typescript: {
alwaysTryTypes: true,
},
},
},
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react-redux',
importNames: ['useSelector'],
message: 'Use "import { useSelector } from \'src/store/utils\'" instead.',
},
{
name: 'react-hooks-testing-library',
importNames: ['renderHook'],
message: "Use \"import { renderHookWith } from 'test-utils/testing-library/renderHookWith'",
},
{
name: 'next/router',
importNames: ['default', 'useRouter', 'Router'],
message: "Use './src/routes' instead.",
},
],
},
],
// Remove unused imports
'unused-imports/no-unused-imports-ts': 'error',
// Checks rules of Hooks
'react-hooks/rules-of-hooks': 'error',
// Checks effect dependencies
'react-hooks/exhaustive-deps': 'warn',
// Forcing explicit typedefs in TS is very nice,
// but can easily annoy TS newcomers - thus let's disable them for now.
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
// Force private members to be prefixed with `_`
'@typescript-eslint/member-naming': [
'warn',
{
private: '^_',
protected: '^_',
},
],
// Allow defining and calling variables/methods that are prefixed with `_`
'no-underscore-dangle': 'off',
// If non-null assertion is wrong, why did they introduce it to TS?
'@typescript-eslint/no-non-null-assertion': 'off',
// I don't see why this would become a problem
// (Sometimes you want to define an interface that extends something but is a different interface,
// that could have some additional props in the future)
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
// This rule is actually detrimental: please see https://github.com/palantir/tslint/issues/3248#issuecomment-470746880
'@typescript-eslint/prefer-interface': 'off',
'unicorn/filename-case': 'off',
// `ChildNode#append()` and `ChildNode#remove()` don't work on IE11, we need to use `.appendChild` instead
'unicorn/prefer-node-append': 'off',
'unicorn/prefer-node-remove': 'off',
// https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
'import/prefer-default-export': 'off',
'import/no-default-export': 2,
// TODO Enable it when https://github.com/benmosher/eslint-plugin-import/pull/1304 gets released
// 'import/no-unresolved': ['error'],
// TODO Remove those 2 lines when https://github.com/benmosher/eslint-plugin-import/pull/1304 gets released
'import/named': 'off',
'import/no-unresolved': 'off',
'import/order': [
'error',
{
groups: [['builtin', 'external'], ['internal', 'parent', 'sibling'], ['index']],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
optionalDependencies: false,
peerDependencies: false,
},
],
'react/no-unescaped-entities': 'off',
'react/no-array-index-key': 'off',
'react/prop-types': 'off',
'react/forbid-prop-types': 'off',
// We've got prettier for that
'react/jsx-wrap-multilines': 'off',
'react/jsx-indent': 'off',
'react/jsx-no-target-blank': 'off',
'react/jsx-props-no-spreading': 'off',
'react/jsx-filename-extension': [
1,
{
extensions: ['.tsx', '.jsx', '.js'],
},
],
'react/sort-comp': [
1,
{
order: [
'static-methods',
'instance-variables',
'type-annotations',
'lifecycle',
'everything-else',
'/^_?handle.+$/',
'/^_?render.+$/',
'render',
],
},
],
// Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md
'react/destructuring-assignment': 'off',
'react/jsx-one-expression-per-line': 'off',
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': 'off',
// TODO enable those but only as warnings,
// So they can be possible during development,
// but won't go onto staging (CI will fail)
'no-alert': 'off',
'no-console': 'off',
'no-debugger': 'off',
'no-param-reassign': 'off',
'no-nested-ternary': 'off',
'class-methods-use-this': 'off',
'no-use-before-define': ['error'],
// Remove restriction on `ForOfStatement` as it's just a highly opinionated rule that doesn't have much merit IMO
// see https://github.com/airbnb/javascript/issues/1271 for more info
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
// line spacing
'padding-line-between-statements': [
'error',
// wildcard inclusions
{
blankLine: 'always',
prev: ['multiline-block-like', 'multiline-const', 'multiline-expression'],
next: '*',
},
{
blankLine: 'always',
prev: '*',
next: ['multiline-block-like', 'multiline-const', 'multiline-expression', 'switch', 'return'],
},
// specific exclusions for case statements
{ blankLine: 'never', prev: 'case', next: 'multiline-block-like' },
{ blankLine: 'never', prev: 'multiline-block-like', next: 'case' },
],
},
overrides: [
{
files: 'bin/*.js',
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
// Allow for devDependencies to be imported
// in the project config, story and test files
{
files: ['bin/**', 'build/**', 'next.config.js', '**/*test.*', '**/*tests.*'],
rules: {
'react/display-name': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
optionalDependencies: false,
peerDependencies: false,
},
],
},
},
// Ignore the filenames match for Next.js (and other vendors) config files
{
files: [
'next-env.d.ts',
'next.config.js',
'pages/**/*.tsx',
'server/index.ts',
'src/utils/styled-components/index.ts',
'src/utils/styled-components/styled-components.ts',
],
rules: {
'import/no-default-export': 'off',
'filenames/match-regex': 'off',
'filenames/match-exported': 'off',
'filenames/no-index': 'off',
},
},
// Turn off `import` for files run directly by node.js
// (they don't support `import` yet)
{
files: ['next.config.js', 'build/**', 'bin/**'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
],
};