-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.js
284 lines (278 loc) · 8.26 KB
/
eslint.config.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
281
282
283
284
// @ts-expect-error No definition for this one
import eslintJs from '@eslint/js';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import standardConfig from 'eslint-config-standard';
import deprecationPlugin from 'eslint-plugin-deprecation';
// @ts-expect-error No definition for this one
import importPlugin from 'eslint-plugin-import';
// @ts-expect-error No definition for this one
import importNewlinesPlugin from 'eslint-plugin-import-newlines';
// @ts-expect-error No definition for this one
import nPlugin from 'eslint-plugin-n';
// @ts-expect-error No definition for this one
import promisePlugin from 'eslint-plugin-promise';
// @ts-expect-error No definition for this one
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
// @ts-expect-error No definition for this one
import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys';
import vitestPlugin from 'eslint-plugin-vitest';
import globals from 'globals';
const EXT_JS = ['.cjs', '.js', '.mjs'];
const EXT_TS = ['.ts', '.tsx'];
const EXT_ALL = [...EXT_JS, ...EXT_TS];
/**
* @internal
* Converts a list of EXT_* defined above to globs
* @param {string[]} exts
* @returns {string[]}
*/
function extsToGlobs (exts) {
return exts.map((e) => `**/*${e}`);
}
export const overrideJs = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off'
};
export const overrideSpec = {
// in the specs we are a little less worried about
// specific correctness, i.e. we can have dangling bits
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'vitest/consistent-test-filename': 'error',
'vitest/consistent-test-it': 'error',
'vitest/max-nested-describe': ['error', { max: 3 }]
};
export const overrideAll = {
// the next 2 enforce isolatedModules & verbatimModuleSyntax
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/no-non-null-assertion': 'error',
// ts itself checks and ignores those starting with _, align the linting
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
vars: 'all',
varsIgnorePattern: '^_'
}
],
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'arrow-parens': ['error', 'always'],
'brace-style': ['error', '1tbs'],
curly: ['error', 'all'],
'default-param-last': 'off', // conflicts with TS version
'deprecation/deprecation': 'error',
'dot-notation': 'off', // conflicts with TS version
'func-style': [
'error',
'declaration',
{
allowArrowFunctions: true
}
],
'function-call-argument-newline': ['error', 'consistent'],
'import-newlines/enforce': [
'error',
{
forceSingleLine: true,
items: 2048
}
],
'import/export': 'error',
'import/extensions': [
'error',
'ignorePackages',
{
cjs: 'always',
js: 'always',
json: 'always',
jsx: 'never',
mjs: 'always',
ts: 'never',
tsx: 'never'
}
],
'import/first': 'error',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',
'import/order': 'off', // conflicts with simple-import-sort
indent: 'off', // required as 'off' since typescript-eslint has own versions
'no-extra-semi': 'error',
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'object-curly-newline': [
'error',
{
ExportDeclaration: { minProperties: 2048 },
ImportDeclaration: { minProperties: 2048 },
ObjectPattern: { minProperties: 2048 }
}
],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', next: '*', prev: ['const', 'let', 'var'] },
{
blankLine: 'any',
next: ['const', 'let', 'var'],
prev: ['const', 'let', 'var']
},
{ blankLine: 'always', next: 'block-like', prev: '*' },
{ blankLine: 'always', next: '*', prev: 'block-like' },
{ blankLine: 'always', next: 'function', prev: '*' },
{ blankLine: 'always', next: '*', prev: 'function' },
{ blankLine: 'always', next: 'try', prev: '*' },
{ blankLine: 'always', next: '*', prev: 'try' },
{ blankLine: 'always', next: 'return', prev: '*' },
{ blankLine: 'always', next: 'import', prev: '*' },
{ blankLine: 'always', next: '*', prev: 'import' },
{ blankLine: 'any', next: 'import', prev: 'import' }
],
semi: ['error', 'always'],
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': [
'error',
{
groups: [
['^\u0000'],
['^[^/\\.]'],
[
'^\\.\\.(?!/?$)',
'^\\.\\./?$',
'^\\./(?=.*/)(?!/?$)',
'^\\.(?!/?$)',
'^\\./?$'
] // local (. last)
]
}
],
'sort-destructure-keys/sort-destructure-keys': [
'error',
{
caseSensitive: true
}
],
'sort-keys': 'error',
'spaced-comment': [
'error',
'always',
{
block: {
// pure export helpers
markers: ['#__PURE__']
},
line: {
// TS reference types
markers: ['/ <reference']
}
}
]
};
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
{
ignores: [
'**/.github/',
'**/.vscode/',
'**/.husky/',
'**/coverage/**',
'**/dist/**',
'**/pnpm-lock.yaml',
'**/pnpm-workspace.yaml'
]
},
{
languageOptions: {
globals: {
...globals.node,
...globals.browser
},
parser: tsParser,
parserOptions: {
ecmaVersion: 'latest',
project: './tsconfig.eslint.json',
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: false
}
},
plugins: {
'@typescript-eslint': tsPlugin,
deprecation: deprecationPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
import: importPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'import-newlines': importNewlinesPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
n: nPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
promise: promisePlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'simple-import-sort': simpleImportSortPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'sort-destructure-keys': sortDestructureKeysPlugin
},
settings: {
'import/extensions': EXT_ALL,
'import/parsers': {
'@typescript-eslint/parser': EXT_TS,
espree: EXT_JS
},
'import/resolver': {
node: {
extensions: EXT_ALL
},
typescript: {
project: './tsconfig.eslint.json'
}
}
}
},
{
files: extsToGlobs(EXT_JS),
rules: {
...overrideJs
}
},
{
files: extsToGlobs(EXT_ALL),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
rules: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintJs.configs.recommended.rules,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...standardConfig.rules,
...tsPlugin.configs['recommended-type-checked'].rules,
...tsPlugin.configs['stylistic-type-checked'].rules,
...overrideAll
}
},
{
files: ['**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
globals: {
...vitestPlugin.environments.env.globals
}
},
plugins: {
vitest: vitestPlugin
},
rules: {
...vitestPlugin.configs.recommended.rules,
...overrideSpec
}
}
];