forked from faker-js/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.ts
266 lines (252 loc) · 7.7 KB
/
eslint.config.ts
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
import { includeIgnoreFile } from '@eslint/compat';
import eslint from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import eslintPluginVitest from '@vitest/eslint-plugin';
import eslintPluginJsdoc from 'eslint-plugin-jsdoc';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import tseslint from 'typescript-eslint';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const gitignorePath = resolve(__dirname, '.gitignore');
const config: ReturnType<typeof tseslint.config> = tseslint.config(
//#region global
includeIgnoreFile(gitignorePath),
{
ignores: [
// Skip some files that don't need linting right now
'.github/workflows/commentCodeGeneration.ts',
'.prettierrc.js',
'docs/.vitepress/components/shims.d.ts',
'docs/.vitepress/shared/utils/slugify.ts',
'docs/.vitepress/theme/index.ts',
'eslint.config.js',
],
},
{
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
//#endregion
//#region eslint (js)
eslint.configs.recommended,
{
rules: {
eqeqeq: ['error', 'always', { null: 'ignore' }],
'logical-assignment-operators': 'error',
'no-else-return': 'error',
'no-restricted-globals': ['error', 'Intl'],
'prefer-exponentiation-operator': 'error',
'prefer-template': 'error',
},
},
//#endregion
//#region typescript-eslint
...tseslint.configs.strictTypeChecked,
{
plugins: {
'@typescript-eslint': tseslint.plugin,
},
languageOptions: {
parserOptions: {
project: true,
warnOnUnsupportedTypeScriptVersion: false,
},
},
rules: {
'@typescript-eslint/array-type': [
'error',
{ default: 'array-simple', readonly: 'generic' },
],
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
format: ['PascalCase'],
selector: ['class', 'interface', 'typeAlias', 'enumMember'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
format: ['PascalCase'],
selector: ['typeParameter'],
prefix: ['T'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
],
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true,
},
],
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: true },
],
'@typescript-eslint/no-unnecessary-condition': 'off', // requires `strictNullChecks` to be enabled
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/restrict-plus-operands': [
'error',
{
allowAny: false,
allowBoolean: false,
allowNullish: false,
allowNumberAndString: true,
allowRegExp: false,
},
],
'@typescript-eslint/restrict-template-expressions': [
'error',
{ allowNumber: true, allowBoolean: true },
],
'@typescript-eslint/switch-exhaustiveness-check': [
'error',
{ requireDefaultForNonUnion: true },
],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'off', // incompatible with our api docs generation
},
},
//#endregion
//#region stylistic
{
plugins: {
'@stylistic': stylistic,
},
rules: {
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'block-like', next: '*' },
],
},
},
//#endregion
//#region unicorn
eslintPluginUnicorn.configs['flat/recommended'],
{
rules: {
'unicorn/import-style': 'off', // subjective & doesn't do anything for us
'unicorn/no-array-callback-reference': 'off', // reduces readability
'unicorn/no-nested-ternary': 'off', // incompatible with prettier
'unicorn/no-null': 'off', // incompatible with TypeScript
'unicorn/no-zero-fractions': 'off', // deactivated to raise awareness of floating operations
'unicorn/number-literal-case': 'off', // incompatible with prettier
'unicorn/numeric-separators-style': 'off', // "magic numbers" may carry specific meaning
'unicorn/prefer-string-raw': 'off', // The additional prefix doesn't help readability
'unicorn/prefer-ternary': 'off', // ternaries aren't always better
// TODO @Shinigami92 2023-09-23: The following rules currently conflict with our code.
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-object-as-default-parameter': 'off',
'unicorn/prefer-export-from': 'off',
'unicorn/prefer-string-slice': 'off',
'unicorn/prevent-abbreviations': 'off',
},
},
//#endregion
//#region jsdoc
eslintPluginJsdoc.configs['flat/recommended-typescript-error'],
{
rules: {
'jsdoc/require-jsdoc': 'off', // Enabled only for src/**/*.ts
'jsdoc/require-returns': 'off',
'jsdoc/sort-tags': [
'error',
{
tagSequence: [
{ tags: ['template'] },
{ tags: ['internal'] },
{ tags: ['param'] },
{ tags: ['returns'] },
{ tags: ['throws'] },
{ tags: ['see'] },
{ tags: ['example'] },
{ tags: ['since'] },
{ tags: ['default'] },
{ tags: ['deprecated'] },
],
},
],
'jsdoc/tag-lines': 'off',
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
//#endregion
//#region prettier
eslintPluginPrettierRecommended,
//#endregion,
//#region overrides
{
files: ['src/**/*.ts'],
rules: {
'no-undef': 'error', // Must override the config from typescript-eslint
'jsdoc/require-jsdoc': 'error',
},
languageOptions: {
// Don't allow any globals in our TypeScript files - unless explicitly ignored
globals: {},
},
},
{
files: ['src/locale/**/*.ts'],
rules: {
'unicorn/filename-case': 'off', // our locale files have a custom naming scheme
},
},
{
files: ['src/definitions/**/*.ts', 'src/locales/**/*.ts'],
rules: {
'unicorn/filename-case': [
'error',
{
case: 'snakeCase',
},
],
'unicorn/text-encoding-identifier-case': 'off',
},
},
{
files: ['test/**/*.spec.ts', 'test/**/*.spec.d.ts'],
plugins: {
vitest: eslintPluginVitest,
},
rules: {
'deprecation/deprecation': 'off',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowAny: true,
},
],
...eslintPluginVitest.configs.recommended.rules,
'vitest/expect-expect': 'off',
'vitest/no-alias-methods': 'error',
'vitest/prefer-each': 'error',
'vitest/prefer-to-have-length': 'error',
'vitest/valid-expect': ['error', { maxArgs: 2 }],
},
settings: {
vitest: {
typecheck: true,
},
},
}
//#endregion
);
export default config;