-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.core.js
232 lines (230 loc) · 7.28 KB
/
.eslintrc.core.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
// basic eslint settings to use via CLI
const banOptions = [
{ name: 'require', message: 'Prefer use `import`' },
{ name: 'lazy', message: 'Prefer use helper `lazyfy`' },
{ name: ['localStorage', '*'], message: 'Please use the `persistent` service' },
];
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
},
plugins: ['@typescript-eslint', 'react-hooks', 'mobx', 'ban'],
extends: [
'airbnb',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'airbnb-typescript', // must be below `@typescript-eslint/*`, e.g. for disabling @typescript-eslint/require-await
'plugin:prettier/recommended',
'plugin:storybook/recommended',
'plugin:mobx/recommended',
'plugin:compat/recommended',
'plugin:eslint-comments/recommended',
],
rules: {
'react/jsx-props-no-spreading': 'off',
'react/no-array-index-key': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'react/no-danger': 'error',
'react/destructuring-assignment': 'off',
'react/jsx-key': [
'error',
{
checkFragmentShorthand: true,
},
],
'react/jsx-no-bind': [
'error',
{
ignoreRefs: true,
allowArrowFunctions: true,
allowFunctions: true,
allowBind: false,
ignoreDOMComponents: true,
},
],
'react/function-component-definition': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/no-unstable-nested-components': 'off',
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
'import/no-cycle': [
'error',
{
maxDepth: 2,
},
],
'import/order': [
'error',
{
groups: [['builtin', 'external'], 'internal', ['parent', 'sibling'], 'index'],
'newlines-between': 'always',
},
],
// off recommended rules
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off', // index signature can be more informative
'@typescript-eslint/prefer-nullish-coalescing': 'off', // part of the old logic can rely on `||`
'@typescript-eslint/no-unsafe-call': 'off', // can be hard for typing
'@typescript-eslint/no-unsafe-member-access': 'off', // can be hard for typing
'@typescript-eslint/no-unsafe-argument': 'off', // enabled only for IDE, +5s to execution time
'@typescript-eslint/no-unsafe-return': 'off', // enabled only for IDE, +5s to execution time
'@typescript-eslint/no-confusing-void-expression': 'off', // enabled only for IDE, +3s to execution time
'@typescript-eslint/no-floating-promises': 'off', // false-positive
'@typescript-eslint/no-unsafe-assignment': 'off', // false-positive
'@typescript-eslint/no-misused-promises': 'off', // false-positive
'@typescript-eslint/unbound-method': 'off', // false-positive
'@typescript-eslint/no-unsafe-enum-comparison': 'off', // false-positive
'@typescript-eslint/lines-between-class-members': 'off', // formatting-related, not recommended for use
// end off recommended rules
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/member-ordering': [
'error',
{ default: ['constructor', 'field', 'method', 'signature'] },
],
'class-methods-use-this': 'off',
'no-console': [
'error',
{
allow: ['info', 'warn', 'error'],
},
],
'func-names': [
'error',
'as-needed',
{
generators: 'never',
},
],
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/label-has-associated-control': [
'error',
{
assert: 'either',
},
],
'react-hooks/rules-of-hooks': 'error',
'consistent-return': 'off',
'no-underscore-dangle': ['error', { allowAfterThis: true, allow: ['__'] }],
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: true, variables: true },
],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description',
},
],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
},
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase', 'snake_case'],
leadingUnderscore: 'allowSingleOrDouble',
},
{
selector: 'method',
format: ['camelCase'],
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'typeParameter',
format: ['PascalCase'],
prefix: ['T'],
},
],
'mobx/missing-observer': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true, varsIgnorePattern: '^R$' },
],
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['date-fns', 'date-fns-tz'],
message: 'Please use the datetime service or import from datetime helpers.',
},
],
paths: [
{
name: 'react-slick',
message: 'Please use Carousel from shared/view/components/Carousel instead.',
},
],
},
],
'ban/ban': ['error', ...banOptions],
'compat/compat': 'off',
'no-restricted-syntax': [
'error',
{
selector: [
'CallExpression[callee.name="autorun"] > ArrowFunctionExpression[async="true"]',
'CallExpression[callee.name="autorun"] > FunctionExpression[async="true"]',
].join(', '),
message: 'autorun() only accepts synchronous functions',
},
{
selector: [
'MethodDefinition[value.async="true"] Decorator[expression.object.name="action"]',
'MethodDefinition[value.async="true"] Decorator[expression.name="action"]',
'PropertyDefinition[value.type="ArrowFunctionExpression"][value.async="true"] Decorator[expression.object.name="action"]',
'PropertyDefinition[value.type="ArrowFunctionExpression"][value.async="true"] Decorator[expression.name="action"]',
].join(', '),
message: '@action must be synchronous function',
},
],
curly: ['error', 'all'],
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
},
overrides: [
{
files: ['**/*.stories.tsx'],
rules: {
'import/no-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/*.test.ts', '**/__tests__/**'],
rules: {
'import/no-extraneous-dependencies': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
],
env: {
browser: true,
node: true,
},
globals: {
window: 'readonly',
},
settings: {
'import/resolver': {
node: {
paths: ['src'],
},
},
},
};