-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheslint.config.js
More file actions
304 lines (274 loc) · 8.55 KB
/
eslint.config.js
File metadata and controls
304 lines (274 loc) · 8.55 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
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { includeIgnoreFile } from '@eslint/compat'
import eslint from '@eslint/js'
import pluginMarkdown from '@eslint/markdown'
import { defineConfig, globalIgnores } from 'eslint/config'
import configPrettier from 'eslint-config-prettier/flat'
import pluginESx from 'eslint-plugin-es-x'
import pluginImport from 'eslint-plugin-import'
import pluginJest from 'eslint-plugin-jest'
import pluginJestDom from 'eslint-plugin-jest-dom'
import pluginJsdoc from 'eslint-plugin-jsdoc'
import pluginNode from 'eslint-plugin-n'
import pluginPromise from 'eslint-plugin-promise'
import globals from 'globals'
import pluginTypeScript from 'typescript-eslint'
const rootPath = resolve(fileURLToPath(new URL('.', import.meta.url)))
const gitignorePath = join(rootPath, '.gitignore')
export default defineConfig([
{
files: ['**/*.{cjs,js,mjs}'],
extends: [
eslint.configs.recommended,
pluginImport.flatConfigs.recommended,
pluginImport.flatConfigs.typescript,
pluginJsdoc.configs['flat/recommended-typescript-flavor'],
pluginPromise.configs['flat/recommended'],
pluginTypeScript.configs.strict,
pluginTypeScript.configs.stylistic,
configPrettier
],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
projectService: true,
tsconfigRootDir: rootPath
}
},
rules: {
// Turn off rules that are handled by TypeScript
// https://typescript-eslint.io/troubleshooting/typed-linting/performance/#eslint-plugin-import
'import/default': 'off',
'import/named': 'off',
'import/namespace': 'off',
'import/no-cycle': 'off',
'import/no-deprecated': 'off',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
'import/no-unused-modules': 'off',
// Always import Node.js packages from `node:*`
'import/enforce-node-protocol-usage': ['error', 'always'],
// Check import or require statements are A-Z ordered
'import/order': [
'error',
{
'alphabetize': { order: 'asc' },
'newlines-between': 'always'
}
],
// Check for valid formatting
'jsdoc/check-line-alignment': [
'warn',
'never',
{
wrapIndent: ' '
}
],
// JSDoc blocks are optional by default
'jsdoc/require-jsdoc': 'off',
// Require hyphens before param description
// Aligns with TSDoc style: https://tsdoc.org/pages/tags/param/
'jsdoc/require-hyphen-before-param-description': 'warn',
// JSDoc @param required in (optional) blocks but
// @param description is not necessary by default
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'error',
'jsdoc/require-param': 'off',
// JSDoc @returns is optional
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns': 'off',
// Maintain new line after description
'jsdoc/tag-lines': [
'warn',
'never',
{
startLines: 1
}
],
// Automatically use template strings
'no-useless-concat': 'error',
'prefer-template': 'error',
// Flow control – avoid continue and else blocks after return statements
// in if statements
'no-continue': 'error',
'no-else-return': 'error',
// Avoid hard to read multi assign statements
'no-multi-assign': 'error',
// Prefer rules that are type aware
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error']
}
},
{
// CommonJS modules allow require statements
files: ['**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off'
}
},
{
// ES modules mandatory file extensions
files: ['**/*.{js,mjs}'],
rules: {
'import/extensions': [
'error',
'always',
{
ignorePackages: true,
pattern: {
cjs: 'always',
js: 'always',
mjs: 'always'
}
}
]
}
},
{
// Configure ESLint for Node.js
files: ['**/*.{cjs,js,mjs}'],
ignores: ['**/assets/js/**'],
extends: [pluginNode.configs['flat/recommended']],
languageOptions: {
globals: globals.node
}
},
{
// Configure ESLint for browsers
files: ['**/assets/js/**/*.js'],
ignores: ['**/*.test.js'],
extends: [
pluginTypeScript.configs.strictTypeChecked,
pluginTypeScript.configs.stylisticTypeChecked,
pluginESx.configs['flat/restrict-to-es2015']
],
languageOptions: {
globals: globals.browser,
parserOptions: {
// Note: Allow ES2015 for import/export syntax
ecmaVersion: 2015
}
},
rules: {
// Allow void return shorthand in arrow functions
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true
}
],
// Check type support for template string implicit `.toString()`
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowBoolean: true,
allowNumber: true
}
],
// Promise.prototype.catch() errors cannot be typed in JavaScript
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
// Babel transpiles ES2020 class fields
'es-x/no-class-fields': 'off',
// Babel transpiles ES2022 class instance fields
'es-x/no-class-instance-fields': 'off',
// Babel transpiles ES2022 class static fields
'es-x/no-class-static-fields': 'off',
// ES modules include ES2016 '[].includes()' coverage
// https://browsersl.ist/#q=supports+es6-module+and+not+supports+array-includes
'es-x/no-array-prototype-includes': 'off',
// Babel transpiles ES2020 `??` nullish coalescing
'es-x/no-nullish-coalescing-operators': 'off',
// ES modules include ES2017 'Object.entries()' coverage
// https://browsersl.ist/#q=supports+es6-module+and+not+supports+object-entries
'es-x/no-object-entries': 'off',
// Babel transpiles optional catch binding
'es-x/no-optional-catch-binding': 'off',
// Babel transpiles ES2020 optional chaining
'es-x/no-optional-chaining': 'off',
// JSDoc blocks are optional but must be valid
'jsdoc/require-jsdoc': [
'error',
{
enableFixer: false,
require: {
FunctionDeclaration: false
}
}
],
// JSDoc @param types are mandatory for JavaScript
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'error',
'jsdoc/require-param': 'off',
// JSDoc @returns is optional
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns': 'off'
}
},
{
// Configure ESLint in test files
files: [
'**/*.test.{cjs,js,mjs}',
'jest?(.*).config.*',
'jest?(.*).setup.*'
],
extends: [
pluginJest.configs['flat/recommended'],
pluginJest.configs['flat/style'],
pluginJestDom.configs['flat/recommended']
],
languageOptions: {
globals: {
...globals.browser,
...pluginJest.environments.globals.globals
}
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
'promise/always-return': 'off',
'promise/catch-or-return': 'off'
}
},
{
// Configure ESLint in Markdown files
files: ['**/*.md'],
extends: [
pluginMarkdown.configs.recommended,
pluginMarkdown.configs.processor
],
language: 'markdown/gfm',
plugins: { markdown: pluginMarkdown }
},
{
// Configure ESLint in Markdown code blocks
files: ['**/*.md/*.{cjs,js,mjs}'],
extends: [pluginTypeScript.configs.disableTypeChecked],
languageOptions: {
globals: globals.browser
},
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'import/no-unresolved': 'off',
'n/no-missing-import': 'off',
'prefer-template': 'off'
}
},
globalIgnores([
'**/compiled/**',
'**/coverage/**',
'**/staticfiles/**',
'htmlcov/**',
'.mypy_cache/**',
// Enable dotfile linting
'!.*',
'node_modules',
'node_modules/.*',
// Prevent CHANGELOG history changes
'CHANGELOG.md'
]),
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns')
])