-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy patheslint.config.mjs
More file actions
213 lines (198 loc) · 5.92 KB
/
Copy patheslint.config.mjs
File metadata and controls
213 lines (198 loc) · 5.92 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
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { includeIgnoreFile } from '@eslint/config-helpers'
import eslint from '@eslint/js'
import pluginMarkdown from '@eslint/markdown'
import configPrettier from 'eslint-config-prettier/flat'
import pluginESx from 'eslint-plugin-es-x'
import pluginJest from 'eslint-plugin-jest'
import pluginJsdoc from 'eslint-plugin-jsdoc'
import pluginNode from 'eslint-plugin-n'
import pluginNodeImport from 'eslint-plugin-node-import'
import pluginPromise from 'eslint-plugin-promise'
import pluginTestingLibrary from 'eslint-plugin-testing-library'
import { defineConfig, globalIgnores } from 'eslint/config'
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,
pluginJsdoc.configs['flat/recommended-typescript-flavor'],
pluginPromise.configs['flat/recommended'],
configPrettier
],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
projectService: true,
tsconfigRootDir: rootPath
}
},
rules: {
// Check for valid formatting
'jsdoc/check-line-alignment': [
'warn',
'never',
{
wrapIndent: ' '
}
],
// JSDoc blocks can use `@preserve` to prevent removal
'jsdoc/check-tag-names': [
'warn',
{
definedTags: ['preserve']
}
],
// 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-redeclare': 'off',
'no-undef': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
]
}
},
{
// Configure ESLint for Node.js
files: ['**/*.{cjs,js,mjs}'],
ignores: ['app/javascripts/**/*.mjs', '!**/*.test.mjs'],
extends: [
pluginTypeScript.configs.strict,
pluginTypeScript.configs.stylistic,
pluginNode.configs['flat/recommended'],
pluginNodeImport.configs['flat/recommended']
],
languageOptions: {
globals: globals.node
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/unbound-method': 'off'
}
},
{
// Configure ESLint for browsers
files: ['app/javascripts/**/*.mjs', '**/*.md/*.{cjs,js,mjs}'],
ignores: ['**/*.test.mjs'],
extends: [
pluginTypeScript.configs.strict,
pluginTypeScript.configs.stylistic,
pluginESx.configs['flat/restrict-to-es2015']
],
languageOptions: {
globals: globals.browser,
parserOptions: {
// Note: Allow ES2015 for import/export syntax
ecmaVersion: 2015
}
},
rules: {
// Babel transpiles ES2022 class static fields
'es-x/no-class-static-fields': 'off',
// Babel transpiles ES2020 optional chaining
'es-x/no-optional-chaining': 'off'
}
},
{
// Configure ESLint in test files
files: ['**/*.test.mjs'],
extends: [
pluginJest.configs['flat/recommended'],
pluginJest.configs['flat/style'],
pluginTestingLibrary.configs['flat/dom']
],
languageOptions: {
globals: pluginJest.environments.globals.globals
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
'promise/always-return': 'off',
'promise/catch-or-return': 'off'
}
},
{
// Configure ESLint in test files (Jest JSDOM environment only)
files: ['**/*.jsdom.test.mjs', '**/jest.jsdom.setup.*'],
languageOptions: {
globals: {
...globals.browser,
...pluginJest.environments.globals.globals
}
}
},
{
// Configure ESLint in test files (Jest Puppeteer environment only)
files: ['**/*.puppeteer.test.mjs', '**/jest.puppeteer.setup.*'],
languageOptions: {
globals: {
...globals.browser,
...pluginJest.environments.globals.globals,
page: 'readonly',
browser: 'readonly',
jestPuppeteer: 'readonly'
}
}
},
{
// Configure ESLint in Markdown files
files: ['**/*.md'],
extends: [pluginMarkdown.configs.processor],
language: 'markdown/gfm'
},
{
// Configure ESLint in Markdown code blocks
files: ['**/*.md/*.{cjs,js,mjs}'],
extends: [pluginTypeScript.configs.disableTypeChecked],
rules: {
'@typescript-eslint/no-unused-vars': 'off'
}
},
globalIgnores([
'**/coverage/',
'**/dist/',
'**/vendor/',
// Prevent CHANGELOG history changes
'CHANGELOG.md'
]),
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns')
])