/
.eslintrc.cjs
315 lines (296 loc) · 11.2 KB
/
.eslintrc.cjs
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
process.env.ESLINT_TSCONFIG = 'tsconfig.json'
module.exports = {
root: true,
/**
* Base on @antfu/[email protected]
* https://github.com/antfu/eslint-config/blob/v0.39.7
*/
extends: [
'@antfu/react',
],
ignorePatterns: [
'!.storybook',
'!.stories',
],
rules: {
/**
* ===================================
* ************ Basic ************
* ===================================
*/
// https://eslint.org/docs/latest/rules/no-console
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L241
'no-console': ['error', { allow: ['warn', 'error', 'debug'] }],
// https://eslint.org/docs/latest/rules/sort-imports
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L380
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: true,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false,
},
],
// https://eslint.org/docs/latest/rules/no-multiple-empty-lines
'no-multiple-empty-lines': [
'error',
{
max: 2,
maxEOF: 1,
maxBOF: 1,
},
],
// https://eslint.org/docs/latest/rules/object-curly-newline
'object-curly-newline': [
'error',
{
ObjectExpression: {
minProperties: 4,
multiline: true,
consistent: true,
},
ObjectPattern: {
minProperties: 4,
multiline: true,
consistent: true,
},
ImportDeclaration: {
minProperties: 4,
multiline: true,
consistent: true,
},
ExportDeclaration: {
minProperties: 4,
multiline: true,
consistent: true,
},
},
],
// https://eslint.org/docs/latest/rules/object-property-newline
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/standard.js#L196
'object-property-newline': ['error', { allowAllPropertiesOnSameLine: false }],
// https://eslint.org/docs/latest/rules/array-bracket-newline
'array-bracket-newline': ['error', 'consistent'],
// https://eslint.org/docs/latest/rules/array-element-newline
'array-element-newline': ['error', 'consistent'],
// https://eslint.org/docs/latest/rules/curly#multi-line
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L221
'curly': ['error', 'multi-line', 'consistent'],
// https://eslint.org/docs/latest/rules/arrow-parens
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L305
'arrow-parens': 'off',
/**
* https://eslint.org/docs/latest/rules/multiline-ternary
* Must using with
* - `operator-linebreak` rule with `before`,
* - and `indent` rule with `flatTernaryExpressions: false`, `offsetTernaryExpressions: false`,
*
* to align the '?' and ':' symbols when using a ternary operator.
*
* ```
* xxx == yyy
* ? zzz
* : null
* ```
*/
'multiline-ternary': [
'error',
'always-multiline',
],
// https://eslint.org/docs/rules/operator-linebreak
'operator-linebreak': [
'error',
'before',
],
// https://github.com/un-es/eslint-plugin-i/blob/fork-release/docs/rules/default.md
// not interpret `module.exports = ...` as a `default` export
'import/default': 'off',
/**
* ===================================
* ********** Typescript **********
* ===================================
*/
// https://eslint.org/docs/latest/rules/quotes#options
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-ts/index.js#L131
'@typescript-eslint/quotes': [
'error',
'single',
{
avoidEscape: true,
allowTemplateLiterals: true,
},
],
// https://typescript-eslint.io/rules/no-inferrable-types
'@typescript-eslint/no-inferrable-types': 'off',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-delimiter-style.md
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
},
],
// https://typescript-eslint.io/rules/consistent-type-imports
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-ts/index.js#L71
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
disallowTypeAnnotations: true,
fixStyle: 'inline-type-imports',
},
],
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-use-before-define.md
'@typescript-eslint/no-use-before-define': 'off',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-floating-promises.md
'@typescript-eslint/no-floating-promises': 'off',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-misused-promises.md
'@typescript-eslint/no-misused-promises': 'off',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-extra-parens.md
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-ts/index.js#L150
'@typescript-eslint/no-extra-parens': 'off',
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-ts/index.js#L78
// https://eslint.org/docs/latest/rules/indent#options
'@typescript-eslint/indent': [
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
offsetTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [
'TSTypeParameterInstantiation',
'TSIntersectionType',
'TSUnionType',
'PropertyDefinition[decorators]',
// 'ConditionalExpression',
// 'TemplateLiteral *',
// 'JSXElement',
// 'JSXElement > *',
// 'JSXAttribute',
// 'JSXIdentifier',
// 'JSXNamespacedName',
// 'JSXMemberExpression',
// 'JSXSpreadAttribute',
// 'JSXExpressionContainer',
// 'JSXOpeningElement',
// 'JSXClosingElement',
// 'JSXFragment',
// 'JSXOpeningFragment',
// 'JSXClosingFragment',
// 'JSXText',
// 'JSXEmptyExpression',
// 'JSXSpreadChild',
// 'TSTypeParameterInstantiation',
// 'FunctionExpression > .params[decorators.length > 0]',
// 'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
// 'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
],
},
],
// https://typescript-eslint.io/rules/restrict-template-expressions/
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-ts/index.js#L50
'@typescript-eslint/restrict-template-expressions': 'off',
/**
* ===================================
* ************ React ************
* ===================================
*/
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
'react/jsx-first-prop-new-line': ['error', 'multiline'],
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
'react/jsx-max-props-per-line': [
'error',
{
maximum: 1,
when: 'multiline',
},
],
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
'react/jsx-wrap-multilines': [
'error',
{
declaration: 'parens-new-line',
assignment: 'parens-new-line',
return: 'parens-new-line',
arrow: 'parens-new-line',
condition: 'parens-new-line',
logical: 'parens-new-line',
prop: 'parens-new-line',
},
],
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
'react/self-closing-comp': 'error',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md
'react/jsx-closing-tag-location': 'error',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
'react/jsx-closing-bracket-location': 'error',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
'react/jsx-boolean-value': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
'react/jsx-curly-brace-presence': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md
'react/jsx-tag-spacing': [
'error',
{
closingSlash: 'allow',
beforeSelfClosing: 'always',
afterOpening: 'never',
beforeClosing: 'never',
},
],
// https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md
'react-hooks/exhaustive-deps': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/display-name.md
'react/display-name': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prop-types.md
'react/prop-types': 'off',
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prop-types.md
'react/no-unescaped-entities': 'off',
// https://eslint.org/docs/latest/rules/jsx-quotes
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-react/index.js#L13
'jsx-quotes': ['error', 'prefer-single'],
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
// `css`: https://emotion.sh/docs/css-prop
// `jsx`,`global`: https://nextjs.org/blog/styling-next-with-styled-jsx
'react/no-unknown-property': ['error', { ignore: ['css', 'jsx', 'global'] }],
/**
* ===================================
* ************ Antfu ************
* ===================================
*/
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L396
'antfu/if-newline': 'off',
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L398
'antfu/top-level-function': 'off',
},
overrides: [
{
files: ['packages/*/src/**/*.{js,ts,tsx}'],
rules: {
// For more compatibility with lower Node.js versions
'unicorn/prefer-node-protocol': 'off',
},
},
],
}