-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheslint.config.mjs
More file actions
390 lines (380 loc) · 14.3 KB
/
eslint.config.mjs
File metadata and controls
390 lines (380 loc) · 14.3 KB
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import globals from 'globals'
import { defineConfig } from 'eslint/config'
import eslint from '@eslint/js'
import tsEslint from 'typescript-eslint'
import stylistic from '@stylistic/eslint-plugin'
import { importX } from 'eslint-plugin-import-x'
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
/* eslint-disable @stylistic/quote-props */
export default defineConfig([
eslint.configs.recommended,
tsEslint.configs.recommended,
tsEslint.configs.stylistic,
importX.flatConfigs.recommended,
importX.flatConfigs.typescript,
stylistic.configs.recommended,
{
files: ['**/*.{js,ts,tsx,mjs,mts}'],
languageOptions: {
parserOptions: {
ecmaVersion: 2023,
tsconfigRootDir: import.meta.dirname,
projectService: true
},
globals: {
...globals.browser,
...globals.node
}
},
linterOptions: {
// Включены в .full файле
reportUnusedDisableDirectives: 'off',
reportUnusedInlineConfigs: 'off'
},
plugins: {
'simple-import-sort': simpleImportSort
},
settings: {
'import-x/extensions': ['.js', '.jsx', '.ts', '.tsx'],
'import-x/cache': { lifetime: 'Infinity' },
'import-x/resolver-next': createTypeScriptImportResolver()
},
rules: {
//#region eslint
'no-constant-condition': ['error', {
// Разрешает while (true)
checkLoops: false
}],
'no-constructor-return': 'error',
'no-unmodified-loop-condition': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-negation': ['error', {
// Запрещает выражения вида (!a < b)
enforceForOrderingRelations: true
}],
'no-unsafe-optional-chaining': ['error', {
// Запрещает математические операции с optional chaining: obj?.foo + bar
disallowArithmeticOperators: true
}],
'use-isnan': ['error', {
// Запрещает arr.indexOf(NaN)
enforceForIndexOf: true
}],
'camelcase': ['error', {
// Отключает проверку ключей в объектах
properties: 'never'
}],
'curly': ['error', 'all'],
'eqeqeq': ['error', 'always'],
'func-style': ['error', 'declaration', {
// Разрешает стрелочные функции
allowArrowFunctions: true
}],
'new-cap': ['error', {
// Не ругается на lowercase 'object' в new Class.object()
properties: false
}],
'no-caller': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-lonely-if': 'error',
'no-multi-assign': 'error',
'no-multi-str': 'error',
'no-new': 'error',
'no-new-object': 'error',
'no-new-wrappers': 'error',
'no-octal-escape': 'error',
'no-proto': 'error',
'no-return-assign': 'error',
'no-sequences': 'error',
'no-undef-init': 'error',
'no-unneeded-ternary': 'error',
'no-useless-computed-key': ['error', {
// Включает проверку для методов класса
enforceForClassMembers: true
}],
'no-useless-concat': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'operator-assignment': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': ['error', {
// Разрешает let, если какая-то переменная при деструктуризации переопределяется
destructuring: 'all'
}],
'prefer-exponentiation-operator': 'error',
'prefer-numeric-literals': 'error',
'prefer-object-has-own': 'error',
'prefer-object-spread': 'error',
'prefer-regex-literals': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'radix': ['error', 'as-needed'],
'yoda': 'error',
//#endregion eslint
//#region eslint-plugin-import
'import-x/no-extraneous-dependencies': 'error',
'import-x/no-absolute-path': 'error',
'import-x/no-dynamic-require': 'error',
'import-x/no-self-import': 'error',
'import-x/no-useless-path-segments': ['error', {
noUselessIndex: true
}],
'import-x/extensions': ['error', 'always', {
js: 'never',
ts: 'never',
tsx: 'never'
}],
'import-x/first': 'error',
'import-x/newline-after-import': 'error',
'import-x/no-default-export': 'error',
'import-x/no-duplicates': 'error',
'import-x/no-restricted-paths': ['error', {
basePath: './src',
zones: [{
// Где применяются ограничения
target: ['lang', 'misc', 'model', 'store'],
// Откуда нельзя импортировать
from: ['actions', 'hooks', 'ui']
}, {
target: ['converters'],
from: ['hooks', 'ui']
}, {
target: ['model/api-types'],
from: ['model/!(api-types)']
}]
}],
'import-x/no-named-as-default-member': 'off',
//#endregion
'simple-import-sort/imports': ['error', {
groups: [[
...['^fs($|/)', '^os$', '^path$', '^child_process$'],
...['^@?electron', '^@?vite', '^vue', '^pinia', '^@vkontakte/vk-qr', '^@floating-ui/dom'],
...['^env', '^model', '^store', '^actions', '^converters', '^lang'],
...['^hooks', '^misc/utils', '^misc'],
...['^main-process', '^\\./', '^ui', '^assets', '.css$']
]]
}],
//#region @typescript-eslint
'@typescript-eslint/array-type': ['error', {
default: 'array-simple', // string[] / Array<string | number>
readonly: 'generic' // ReadonlyArray<string> / ReadonlyArray<string | number>
}],
'@typescript-eslint/ban-ts-comment': ['error', {
// Запрещаем разрешенный по умолчанию @ts-check
'ts-check': true
}],
'@typescript-eslint/no-restricted-types': ['error', {
types: {
'JSX.Element': {
message: 'Use JSXElement type from misc/utils',
fixWith: 'JSXElement'
}
}
}],
'@typescript-eslint/naming-convention': ['error', {
// Разрешаем называть типы только в PascalCase
selector: 'typeLike',
format: ['PascalCase']
}],
'@typescript-eslint/no-confusing-void-expression': ['error', {
// Разрешаем () => fnThatReturnVoid()
ignoreArrowShorthand: true
}],
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['error', {
ignorePrimitives: {
string: true
}
}],
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/switch-exhaustiveness-check': ['error', {
requireDefaultForNonUnion: true,
considerDefaultExhaustiveForUnions: true
}],
'@typescript-eslint/no-array-delete': 'error',
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
/**
* Далее идут правила, которые расширяют eslint-правила.
* Сами оригинальные eslint-правила должны быть выключены
*/
'@typescript-eslint/default-param-last': 'error',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-expressions': ['error', {
// Разрешает fn && fn()
allowShortCircuit: true
}],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-unnecessary-template-expression': 'error',
'@typescript-eslint/prefer-destructuring': ['error', {
// false здесь означает, что проверяться такие кейсы не будут.
// Для массивов я считаю нормальным многие варианты использования:
// const id = match[1];
// const [, type, id] = match;
VariableDeclarator: {
array: false,
object: true
},
// Отключаем форсирование выражений [foo] = array
AssignmentExpression: {
array: false,
object: false
}
}],
'@typescript-eslint/no-restricted-imports': ['error', {
patterns: [
{
group: ['actions/*'],
message: 'Use \'actions\' instead'
},
{
group: ['assets/icons/*'],
message: 'Use \'assets/icons\' instead'
},
{
group: ['hooks/*'],
message: 'Use \'hooks\' instead'
},
{
group: ['ui/modals/parts/*'],
message: 'Use \'ui/modals/parts\' instead'
}
]
}],
// '@typescript-eslint/no-unnecessary-type-conversion': 'error',
//#endregion
//#region stylistic
'@stylistic/array-bracket-newline': ['error', 'consistent'],
'@stylistic/array-element-newline': ['error', 'consistent'],
'@stylistic/arrow-parens': ['off', 'always'],
'@stylistic/brace-style': ['error', '1tbs'],
'@stylistic/comma-dangle': ['error', 'never'],
// Не считает комментарии за элементы
// https://github.com/eslint-stylistic/eslint-stylistic/issues/675
// '@stylistic/curly-newline': ['error', { minElements: 1 }],
'@stylistic/function-call-argument-newline': ['error', 'consistent'],
'@stylistic/function-call-spacing': 'error',
'@stylistic/function-paren-newline': ['error', 'multiline-arguments'],
'@stylistic/generator-star-spacing': ['error', {
// function* generator() {}
after: true,
// const generator = function*() {}
anonymous: 'neither',
// const obj = { *generator() {} }
method: 'before'
}],
'@stylistic/implicit-arrow-linebreak': 'error',
'@stylistic/indent': ['error', 2, {
// По умолчанию внутри switch была отключена табуляция
SwitchCase: 1,
ignoredNodes: ['TSMappedType > TSTypeReference', 'TSUnionType > TSTypeLiteral']
}],
// Считает юнион типы за бинарные операции
// https://github.com/eslint-stylistic/eslint-stylistic/issues/676
'@stylistic/indent-binary-ops': 'off',
'@stylistic/jsx-curly-spacing': ['error', {
when: 'never',
children: true,
attributes: true
}],
'@stylistic/jsx-first-prop-new-line': ['error', 'multiline'],
'@stylistic/jsx-one-expression-per-line': 'off',
'@stylistic/jsx-self-closing-comp': 'error',
'@stylistic/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: 'ignore',
propertyValue: 'parens-new-line'
}],
'@stylistic/linebreak-style': 'error',
'@stylistic/max-len': ['error', {
code: 100,
ignoreStrings: true,
ignoreRegExpLiterals: true,
ignoreUrls: true
}],
'@stylistic/multiline-ternary': ['error', 'always-multiline', { ignoreJSX: true }],
'@stylistic/no-confusing-arrow': 'error',
'@stylistic/no-extra-semi': 'error',
// Включено в full файле
'@stylistic/no-multiple-empty-lines': 'off',
// Включено в full файле
'@stylistic/no-trailing-spaces': 'off',
'@stylistic/object-curly-newline': ['error', { consistent: true }],
'@stylistic/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }],
'@stylistic/operator-linebreak': ['error', 'after', {
overrides: {
'?': 'before',
':': 'before',
// Правило считает TS Union и Binary Operator за одно и то же, поэтому игнорим
'|': 'ignore'
}
}],
// Включено в full файле
'@stylistic/padded-blocks': 'off',
'@stylistic/quote-props': ['error', 'as-needed'],
'@stylistic/semi-style': 'error',
'@stylistic/space-before-function-paren': ['error', {
named: 'never',
asyncArrow: 'always',
anonymous: 'always'
}],
'@stylistic/spaced-comment': ['error', 'always', {
markers: ['#region', '#endregion']
}],
'@stylistic/switch-colon-spacing': 'error'
//#endregion
}
},
{
files: ['**/*.{ts,tsx,mts}'],
extends: [
tsEslint.configs.recommendedTypeChecked,
tsEslint.configs.stylisticTypeChecked
],
rules: {
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': ['error', {
checksVoidReturn: {
// fn(async () => {}), ожидая () => void
arguments: false,
// <div fn={async () => {}} />, ожидая () => void
attributes: false,
// fn: async () => {}, ожидая () => void
properties: false
}
}],
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/prefer-regexp-exec': 'off',
// Включено в full файле
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-misused-spread': 'error'
}
},
{
files: ['build/*.ts', '**/*.test.ts', '**/*.{mjs,mts}'],
rules: {
'import-x/no-extraneous-dependencies': 'off',
'import-x/no-default-export': 'off',
'import-x/no-unused-modules': 'off',
'import-x/extensions': 'off',
'simple-import-sort/imports': 'off'
}
}
])