-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path.eslintrc.cjs
More file actions
310 lines (294 loc) · 8.29 KB
/
.eslintrc.cjs
File metadata and controls
310 lines (294 loc) · 8.29 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
const path = require('node:path');
const MAX_LINE_LENGTH = 120;
/**
* ESLint rules.
*
* @see {@link https://eslint.org/docs/v8.x/rules/}
*/
const ESLINT_RULES = {
indent: 'off',
'no-bitwise': 'off',
'no-new': 'off',
'no-continue': 'off',
'arrow-body-style': 'off',
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-constant-condition': ['error', { checkLoops: false }],
'max-len': [
'error',
{
code: MAX_LINE_LENGTH,
comments: MAX_LINE_LENGTH,
tabWidth: 4,
ignoreUrls: true,
ignoreTrailingComments: false,
ignoreComments: false,
},
],
// Sort members of import statements, e.g. `import { B, A } from 'module';` -> `import { A, B } from 'module';`
// Note: imports themself are sorted by import/order rule
'sort-imports': ['error', {
ignoreCase: true,
// Avoid conflict with import/order rule
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],
};
/**
* TypeScript ESLint rules.
*
* @see {@link https://typescript-eslint.io/rules/}
*/
const TYPESCRIPT_ESLINT_RULES = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/member-delimiter-style': 'error',
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'explicit',
overrides: {
accessors: 'explicit',
constructors: 'no-public',
methods: 'explicit',
properties: 'off',
parameterProperties: 'explicit',
},
},
],
// Force proper import and export of types
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/consistent-type-exports': [
'error',
{
fixMixedExportsWithInlineTypeSpecifier: true,
},
],
};
/**
* Import plugin rules.
*
* @see {@link https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules}
*/
const IMPORT_PLUGIN_RULES = {
'import/prefer-default-export': 'off',
'import-newlines/enforce': ['error', 3, MAX_LINE_LENGTH],
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
// Split external and internal imports with an empty line
'import/order': [
'error',
{
groups: [
// Built-in Node.js modules
'builtin',
// External packages
'external',
// Parent modules should be in the second place, e.g. `import { foo } from '../bar';`
'parent',
// Sibling modules should be in the third place, e.g. `import { foo } from './bar';`
'sibling',
// All other imports should be in the last place
],
alphabetize: { order: 'asc', caseInsensitive: true },
'newlines-between': 'always',
},
],
};
/**
* JSDoc plugin rules.
*
* @see {@link https://github.com/gajus/eslint-plugin-jsdoc?tab=readme-ov-file#user-content-eslint-plugin-jsdoc-rules}
*/
const JSDOC_PLUGIN_RULES = {
// Types are described in TypeScript
'jsdoc/require-param-type': 'off',
'jsdoc/require-throws-type': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-param-description': 'error',
'jsdoc/require-property-description': 'error',
'jsdoc/require-returns-description': 'error',
'jsdoc/require-returns': 'error',
'jsdoc/require-param': 'error',
'jsdoc/require-returns-check': 'error',
'jsdoc/check-tag-names': [
'warn',
{
// Define additional tags
// https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-tag-names.md#definedtags
definedTags: ['note'],
},
],
'jsdoc/require-hyphen-before-param-description': ['error', 'never'],
'jsdoc/require-jsdoc': [
'error',
{
contexts: [
'ClassDeclaration',
'ClassProperty',
'PropertyDefinition',
'FunctionDeclaration',
'MethodDefinition',
],
},
],
'jsdoc/require-description': [
'error',
{
contexts: [
'ClassDeclaration',
'ClassProperty',
'PropertyDefinition',
'FunctionDeclaration',
'MethodDefinition',
],
},
],
'jsdoc/require-description-complete-sentence': [
'error',
{
abbreviations: [
'e.g.',
'i.e.',
],
},
],
'jsdoc/multiline-blocks': [
'error',
{
noSingleLineBlocks: true,
singleLineTags: [
'inheritdoc',
],
},
],
'jsdoc/tag-lines': [
'error',
'any',
{
startLines: 1,
},
],
'jsdoc/sort-tags': [
'error',
{
linesBetween: 1,
tagSequence: [
{ tags: ['file'] },
{ tags: ['template'] },
{ tags: ['see'] },
{ tags: ['param'] },
{ tags: ['returns'] },
{ tags: ['throws'] },
{ tags: ['example'] },
],
},
],
};
/**
* N plugin rules.
*
* @see {@link https://github.com/eslint-community/eslint-plugin-n?tab=readme-ov-file#-rules}
*/
const N_PLUGIN_RULES = {
// Import plugin is enough, also, this rule requires extensions in ESM, but we use bundler resolution
'n/no-missing-import': 'off',
'n/no-unpublished-import': 'off',
// Require using node protocol for node modules, e.g. `node:fs` instead of `fs`.
'n/prefer-node-protocol': 'error',
// Prefer `/promises` API for `fs` and `dns` modules, if the corresponding imports are used.
'n/prefer-promises/fs': 'error',
'n/prefer-promises/dns': 'error',
};
/**
* Boundaries plugin rules.
*
* @see {@link https://github.com/javierbrea/eslint-plugin-boundaries#readme}
*/
const BOUNDARIES_PLUGIN_RULES = {
'boundaries/element-types': ['error', {
default: 'allow',
rules: [
{
from: 'client',
allow: ['client'],
},
{
from: 'server',
allow: ['server'],
},
// TODO: Add more rules, like helpers only can import helpers, etc.
],
}],
};
/**
* Merges multiple rule sets into a single object.
*
* @param ruleSets The rule sets to merge.
*
* @returns The merged rule set.
*/
function mergeRules(...ruleSets) {
const merged = {};
for (const rules of ruleSets) {
for (const [key, value] of Object.entries(rules)) {
if (merged[key]) {
throw new Error(`Duplicate ESLint rule: ${key}`);
}
merged[key] = value;
}
}
return merged;
}
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'import',
'import-newlines',
'@typescript-eslint',
'n',
'boundaries',
],
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:jsdoc/recommended',
'plugin:jsdoc/recommended-typescript',
'plugin:n/recommended',
],
ignorePatterns: [
'out',
'coverage',
],
settings: {
'boundaries/elements': [
{
type: 'client',
pattern: 'client',
mode: 'folder',
},
{
type: 'server',
pattern: 'server',
mode: 'folder',
},
],
},
rules: mergeRules(
ESLINT_RULES,
TYPESCRIPT_ESLINT_RULES,
IMPORT_PLUGIN_RULES,
JSDOC_PLUGIN_RULES,
N_PLUGIN_RULES,
BOUNDARIES_PLUGIN_RULES,
),
};