-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
224 lines (176 loc) · 6.99 KB
/
eslint.config.mjs
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
// @ts-check
import eslint from '@eslint/js';
import * as tsParser from '@typescript-eslint/parser';
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
import eslintPluginImportX from 'eslint-plugin-import-x';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import unusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';
import tseslint, { configs as tsconfigs } from 'typescript-eslint';
export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tsconfigs.strictTypeChecked,
eslintPluginImportX.flatConfigs.recommended,
eslintPluginImportX.flatConfigs.typescript,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver-next': [
createTypeScriptImportResolver({
alwaysTryTypes: true,
project: '<root>/tsconfig.json',
extensions: ['.js', '.ts'],
}),
],
},
plugins: {
'unused-imports': unusedImports,
},
rules: {
// @typescript-eslint rules ----->
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-deprecated': 'error',
// No magic numbers
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': 'error',
// Disallow empty functions
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error',
// Enforce using a particular method signature syntax
'@typescript-eslint/method-signature-style': 'error',
// Enforce default parameters to be last
'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'error',
// Require the Record type
'@typescript-eslint/consistent-indexed-object-style': 'error',
// Require each enum member value to be explicitly initialized
'@typescript-eslint/prefer-enum-initializers': 'error',
// Disallow the use of variables before they are defined
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'error',
// Require any function or method that returns a Promise to be marked async.
'@typescript-eslint/promise-function-async': 'error',
// Disallow certain types in boolean expressions
'@typescript-eslint/strict-boolean-expressions': 'error',
// Disallow classes used as namespaces.
// Override typescript-eslint strict to allow empty Module classes with decorators
'@typescript-eslint/no-extraneous-class': ['error', {
/** Whether to allow extraneous classes that include a decorator. */
allowWithDecorator: true,
}],
// Enforce template literal expressions to be of `string` type
// Override typescript-eslint strictTyped to remove this rule.
'@typescript-eslint/restrict-template-expressions': 'off',
// Disallow unused variables.
// Override typescript-eslint recommended config to allow unused variables starting with _
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
],
// <----- @typescript-eslint rules
// eslint rules ----->
eqeqeq: ['error', 'always', { null: 'ignore' }],
yoda: ['error', 'never'],
// Disallow await inside of loops
'no-await-in-loop': 'error',
// Disallow else blocks after return statements in if statements
'no-else-return': 'error',
// Enforce consistent function declarations as `function xyz()`
'func-style': ['error', 'declaration'],
// Require default cases in switch statements
'default-case': 'error',
'default-case-last': 'error',
// Disallow assignments that can lead to race conditions due to usage of `await` or `yield`
'require-atomic-updates': ['error', { 'allowProperties': true }],
// Enforce a maximum number of parameters in function definitions
'max-params': ['error', 3],
// Disallow `Array` constructors
'no-array-constructor': 'error',
// Disallow bitwise operators
'no-bitwise': 'error',
// Disallow the use of alert, confirm, and prompt
'no-alert': 'error',
// Disallow the use of `arguments.caller` or `arguments.callee`
'no-caller': 'error',
// Disallow extending native types such as Object.prototype.extra = 55;
'no-extend-native': 'error',
// Disallow the use of eval()
'no-eval': 'error',
// Disallow unnecessary calls to .bind()
'no-extra-bind': 'error',
// Disallow shorthand type conversions, use explicit functions
'no-implicit-coercion': 'error',
// Disallow nested ternary expressions
'no-nested-ternary': 'error',
// Disallow the unary operators ++ and --
'no-plusplus': ['error', { "allowForLoopAfterthoughts": true } ],
// Disallow javascript: URLs. ex: location.href = "javascript:void(0)";
'no-script-url': 'error',
// Disallow ternary operators when simpler alternatives exist
'no-unneeded-ternary': 'error',
// Disallow unnecessary calls to `.call()` and `.apply()`
'no-useless-call': 'error',
// <----- eslint rules
// Style imports :
// https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/
// Consistently add inline `type` to imports & exports
'@typescript-eslint/consistent-type-exports': ['error', { fixMixedExportsWithInlineTypeSpecifier: true }],
'@typescript-eslint/consistent-type-imports': 'error',
'import-x/consistent-type-specifier-style': ['error', 'prefer-inline'],
'import-x/no-duplicates': ['error', { 'prefer-inline': true }],
// Alphabetical order imports
'import-x/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
},
],
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
},
],
// Find and remove unused es6 module imports
'unused-imports/no-unused-imports': 'error',
},
},
);