-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.js
More file actions
226 lines (212 loc) · 5.99 KB
/
eslint.config.js
File metadata and controls
226 lines (212 loc) · 5.99 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
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 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}'],
extends: [
eslint.configs.recommended,
pluginImport.flatConfigs.recommended,
pluginImport.flatConfigs.typescript,
pluginJsdoc.configs['flat/recommended-typescript-flavor'],
pluginPromise.configs['flat/recommended'],
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 but must be valid
'jsdoc/require-jsdoc': [
'error',
{
enableFixer: false,
require: {
FunctionDeclaration: false
}
}
],
// 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'
},
settings: {
'import/resolver': {
node: true,
typescript: true
}
}
},
{
// Configure ESLint for ES modules
files: ['**/*.js'],
rules: {
'import/extensions': [
'error',
'always',
{
ignorePackages: true,
pattern: {
cjs: 'always',
js: 'always',
mjs: 'always'
}
}
]
}
},
{
// Configure ESLint for CommonJS modules
files: ['**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off'
}
},
{
// Configure ESLint for Node.js
files: ['**/*.{cjs,js}'],
ignores: [
'lib/javascripts/**/*.js',
'testapp/app/javascripts/**/*.js',
'!**/*.test.js'
],
extends: [
pluginTypeScript.configs.strict,
pluginTypeScript.configs.stylistic,
pluginNode.configs['flat/recommended']
],
languageOptions: {
globals: globals.node
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
]
}
},
{
// Configure ESLint for browsers
files: ['lib/javascripts/**/*.js', 'testapp/app/javascripts/**/*.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
}
}
},
{
// Configure ESLint in test files
files: ['**/*.test.js'],
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.processor],
language: 'markdown/gfm'
},
{
// Configure ESLint in Markdown code blocks
files: ['**/*.md/*.{cjs,js}'],
extends: [pluginTypeScript.configs.disableTypeChecked],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'n/no-missing-import': ['error', { resolvePaths: ['./testapp'] }],
'no-undef': 'off'
}
},
globalIgnores([
'**/public/**',
// Enable dotfile linting
'!.*',
'node_modules',
'node_modules/.*',
// Prevent CHANGELOG history changes
'CHANGELOG.md'
]),
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns')
])