-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.eslintrc.cjs
More file actions
243 lines (231 loc) · 6.59 KB
/
Copy path.eslintrc.cjs
File metadata and controls
243 lines (231 loc) · 6.59 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
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,
/**
* Ignore calls to logger, e.g. logger.error(), because of the long string.
*/
ignorePattern: 'logger\\.',
},
],
// 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'],
}],
};
/**
* 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, e.g. `import { foo } from '../bar';`
'parent',
// Sibling modules, e.g. `import { foo } from './bar';`
'sibling',
// All other imports
],
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/no-undefined-types': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-throws-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',
// 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',
'n/hashbang': [
'error',
{
// This rule reads the bin property from package.json, and only allows shebangs for that file.
// But since we transform the source files to the dist folder, we need to convert the paths.
convertPath: [
{
include: ['src/**/*.ts'],
replace: ['^src/(.+)\\.ts$', 'dist/$1.js'],
},
],
},
],
};
/**
* 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,
parserOptions: {
ecmaVersion: 'latest',
},
plugins: [
'import',
'import-newlines',
'n',
],
extends: [
'airbnb-base',
'plugin:jsdoc/recommended',
'plugin:n/recommended',
],
ignorePatterns: [
'dist',
'coverage',
],
rules: mergeRules(
ESLINT_RULES,
IMPORT_PLUGIN_RULES,
JSDOC_PLUGIN_RULES,
N_PLUGIN_RULES,
),
};