-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.cjs
209 lines (198 loc) · 6.36 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
// @ts-check
const FILES = {
configs: ['**/*{rc,.config}.{js,cjs,mjs,ts,cts,mts}', 'src/tests/**/*'],
test: '{app,pages,src}/**/*.{spec,test}.{js,jsx,ts,tsx}',
js: '**/*.{js,cjs,mjs}',
tsSrc: 'src/**/*.{ts,tsx}',
tsRouter: '{app,pages}/**/*.{ts,tsx}',
ts: '{src,app,pages}/**/*.{ts,tsx}',
};
const shared = {
plugins: [
'import',
'@typescript-eslint',
'@feature-sliced/eslint-plugin-messages',
'@stylistic/ts',
'vitest',
'testing-library',
'jest-dom',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'airbnb',
'airbnb/hooks',
'airbnb-typescript',
'plugin:import/recommended',
'plugin:import/react',
'plugin:import/typescript',
'plugin:@tanstack/eslint-plugin-query/recommended',
'@feature-sliced',
'plugin:testing-library/react',
'plugin:jest-dom/recommended',
'next/core-web-vitals',
'prettier',
],
};
/** @type {import('eslint').Linter.ConfigOverride[]} */
const overrides = [
/** airbnb rules override */
{
files: FILES.ts,
rules: {
'import/prefer-default-export': 'off',
'no-underscore-dangle': 'off',
},
},
/** enable void usage for lambdas, promises, etc. */
{
files: FILES.ts,
rules: {
'no-void': 'off',
'@typescript-eslint/no-meaningless-void-operator': 'off',
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreVoidOperator: true }],
},
},
/** allow nextjs pages router to import from fsd pages and _app */
{
files: FILES.tsRouter,
rules: {
'boundaries/element-types': 'off',
'import/no-internal-modules': 'off', // fsd linter banned `~/src/_app` imports
},
},
/** some custom rules */
{
files: FILES.ts,
rules: {
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'never' }],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/consistent-type-exports': ['error', { fixMixedExportsWithInlineTypeSpecifier: true }],
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'react/jsx-props-no-spreading': 'off',
'react/function-component-definition': ['error', { unnamedComponents: 'arrow-function' }],
'react/no-array-index-key': 'off',
'curly': ['error', 'all'],
'consistent-return': ['error', { treatUndefinedAsUnspecified: true }],
'import/no-cycle': 'error',
'jsx-a11y/label-has-associated-control': 'off', // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/966
'max-statements': ['error', 15, { ignoreTopLevelFunctions: true }],
},
},
/** some thor's rules */
{
files: FILES.ts,
rules: {
'complexity': ['error', 12],
'max-depth': ['error', 4],
'max-nested-callbacks': ['error', 4],
'no-constant-binary-expression': 'error',
'no-implicit-coercion': 'error',
'no-negated-condition': 'error',
'padding-line-between-statements': ['error', { blankLine: 'always', prev: '*', next: 'return' }],
'object-shorthand': 'error',
'require-atomic-updates': 'error',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import/no-empty-named-blocks': 'error',
'import/no-useless-path-segments': ['error', { noUselessIndex: true }],
'import/no-duplicates': ['error', { considerQueryString: true }],
'import/order': [
'error',
{
'newlines-between': 'always',
'groups': ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
},
],
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: true,
},
],
'@typescript-eslint/restrict-plus-operands': [
'error',
{ allowNumberAndString: false, skipCompoundAssignments: false },
],
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/no-shadow': [
'error',
{
hoist: 'all',
allow: ['resolve', 'reject', 'done', 'next', 'err', 'error'],
ignoreTypeValueShadow: true,
ignoreFunctionTypeParameterNameValueShadow: true,
},
],
'no-return-await': 'off',
'@typescript-eslint/return-await': 'error',
'@stylistic/ts/padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: ['case', 'default', 'block', 'block-like', 'multiline-block-like', 'interface', 'type'],
next: '*',
},
{
blankLine: 'always',
prev: '*',
next: ['export'],
},
{
blankLine: 'any',
prev: ['function-overload', 'export'],
next: ['function-overload', 'function', 'export'],
},
{
blankLine: 'any',
prev: ['const', 'let'],
next: ['const', 'let'],
},
{
blankLine: 'always',
prev: '*',
next: ['switch', 'while', 'try', 'return', 'if', 'interface', 'type', 'function'],
},
],
},
},
/** disable some rules for test files */
{
files: FILES.test,
rules: {
'max-statements': ['error', 10, { ignoreTopLevelFunctions: true }],
},
},
/** disable specific rules for config files */
{
files: FILES.configs,
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
},
/** disable type-aware linting for js files */
{
files: FILES.js,
extends: ['plugin:@typescript-eslint/disable-type-checked'],
},
];
/** @type {import('eslint').Linter.Config} */
const config = {
noInlineConfig: true,
reportUnusedDisableDirectives: true,
parser: '@typescript-eslint/parser',
parserOptions: { project: true },
processor: '@feature-sliced/messages/fs',
...shared,
overrides,
};
module.exports = config;