@rhapsodic/eslint-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +394 -0
- package/dist/index.d.mts +10652 -0
- package/dist/index.mjs +890 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
|
|
4
|
+
Copyright (c) 2025-PRESENT Svyatoslav Fyodorov<https://github.com/intelrug>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# @rhapsodic/eslint-config
|
|
2
|
+
|
|
3
|
+
- Auto fix for formatting
|
|
4
|
+
- Reasonable defaults, best practices, only one line of config
|
|
5
|
+
- Designed to work with TypeScript, Vue. Out-of-box.
|
|
6
|
+
- Opinionated, but [very customizable](#customization)
|
|
7
|
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
8
|
+
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
9
|
+
- Sorted imports, dangling commas
|
|
10
|
+
- Single quotes, no semi
|
|
11
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
12
|
+
- Requires ESLint v9.5.0+
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### Starter Wizard
|
|
17
|
+
|
|
18
|
+
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm dlx @rhapsodic/eslint-config@latest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Manual Install
|
|
25
|
+
|
|
26
|
+
If you prefer to set up manually:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm i -D eslint @rhapsodic/eslint-config
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
And create `eslint.config.mjs` in your project root:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// eslint.config.mjs
|
|
36
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
37
|
+
|
|
38
|
+
export default rhapsodic()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
<details>
|
|
42
|
+
<summary>
|
|
43
|
+
Combined with legacy config:
|
|
44
|
+
</summary>
|
|
45
|
+
|
|
46
|
+
If you still use some configs from the legacy eslintrc format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// eslint.config.mjs
|
|
50
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
51
|
+
import { FlatCompat } from '@eslint/eslintrc'
|
|
52
|
+
|
|
53
|
+
const compat = new FlatCompat()
|
|
54
|
+
|
|
55
|
+
export default rhapsodic(
|
|
56
|
+
{
|
|
57
|
+
ignores: [],
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// Legacy config
|
|
61
|
+
...compat.config({
|
|
62
|
+
extends: [
|
|
63
|
+
'eslint:recommended',
|
|
64
|
+
// Other extends...
|
|
65
|
+
],
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Other flat configs...
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
73
|
+
|
|
74
|
+
</details>
|
|
75
|
+
|
|
76
|
+
### Add script for package.json
|
|
77
|
+
|
|
78
|
+
For example:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"scripts": {
|
|
83
|
+
"lint": "eslint",
|
|
84
|
+
"lint:fix": "eslint --fix"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## IDE Support (auto fix on save)
|
|
90
|
+
|
|
91
|
+
<details>
|
|
92
|
+
<summary>🟦 VS Code support</summary>
|
|
93
|
+
|
|
94
|
+
<br>
|
|
95
|
+
|
|
96
|
+
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
97
|
+
|
|
98
|
+
Add the following settings to your `.vscode/settings.json`:
|
|
99
|
+
|
|
100
|
+
```jsonc
|
|
101
|
+
{
|
|
102
|
+
// Disable the default formatter, use eslint instead
|
|
103
|
+
"prettier.enable": false,
|
|
104
|
+
"editor.formatOnSave": false,
|
|
105
|
+
|
|
106
|
+
// Auto fix
|
|
107
|
+
"editor.codeActionsOnSave": {
|
|
108
|
+
"source.fixAll.eslint": "explicit",
|
|
109
|
+
"source.organizeImports": "never"
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
// Enable eslint for all supported languages
|
|
113
|
+
"eslint.validate": [
|
|
114
|
+
"javascript",
|
|
115
|
+
"typescript",
|
|
116
|
+
"vue"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
</details>
|
|
122
|
+
|
|
123
|
+
## Customization
|
|
124
|
+
Normally you only need to import the `rhapsodic` preset:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
// eslint.config.js
|
|
128
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
129
|
+
|
|
130
|
+
export default rhapsodic()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
And that's it! Or you can configure each integration individually, for example:
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
// eslint.config.js
|
|
137
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
138
|
+
|
|
139
|
+
export default rhapsodic({
|
|
140
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
141
|
+
// The `ignores` option in the option (first argument) is specifically treated to always be global ignores
|
|
142
|
+
// And will **extend** the config's default ignores, not override them
|
|
143
|
+
// You can also pass a function to modify the default ignores
|
|
144
|
+
ignores: [
|
|
145
|
+
'**/fixtures',
|
|
146
|
+
// ...globs
|
|
147
|
+
],
|
|
148
|
+
|
|
149
|
+
// Enable stylistic formatting rules
|
|
150
|
+
stylistic: true,
|
|
151
|
+
|
|
152
|
+
// Or customize the stylistic rules
|
|
153
|
+
stylistic: {
|
|
154
|
+
indent: 2, // 4, or 'tab'
|
|
155
|
+
quotes: 'single', // or 'double'
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// TypeScript and Vue are autodetected, you can also explicitly enable them:
|
|
159
|
+
typescript: true,
|
|
160
|
+
vue: true,
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The `rhapsodic` factory function also accepts any number of arbitrary custom config overrides:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
// eslint.config.js
|
|
168
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
169
|
+
|
|
170
|
+
export default rhapsodic(
|
|
171
|
+
{
|
|
172
|
+
// Configures for rhapsodic's config
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// From the second arguments they are ESLint Flat Configs
|
|
176
|
+
// you can have multiple configs
|
|
177
|
+
{
|
|
178
|
+
files: ['**/*.ts'],
|
|
179
|
+
rules: {},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
rules: {},
|
|
183
|
+
},
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Going more advanced, you can also import fine-grained configs and compose them as you wish:
|
|
188
|
+
|
|
189
|
+
<details>
|
|
190
|
+
<summary>Advanced Example</summary>
|
|
191
|
+
|
|
192
|
+
We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
// eslint.config.js
|
|
196
|
+
import {
|
|
197
|
+
combine,
|
|
198
|
+
ignores,
|
|
199
|
+
imports,
|
|
200
|
+
javascript,
|
|
201
|
+
stylistic,
|
|
202
|
+
typescript,
|
|
203
|
+
unicorn,
|
|
204
|
+
vue,
|
|
205
|
+
} from '@rhapsodic/eslint-config'
|
|
206
|
+
|
|
207
|
+
export default combine(
|
|
208
|
+
ignores(),
|
|
209
|
+
javascript(/* Options */),
|
|
210
|
+
imports(),
|
|
211
|
+
unicorn(),
|
|
212
|
+
typescript(/* Options */),
|
|
213
|
+
stylistic(),
|
|
214
|
+
vue(),
|
|
215
|
+
)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
</details>
|
|
219
|
+
|
|
220
|
+
Check out the [configs](https://github.com/rhapsodic/eslint-config/blob/main/src/configs) and [factory](https://github.com/rhapsodic/eslint-config/blob/main/src/factory.ts) for more details.
|
|
221
|
+
|
|
222
|
+
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
|
|
223
|
+
|
|
224
|
+
### Rules Overrides
|
|
225
|
+
|
|
226
|
+
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
// eslint.config.js
|
|
230
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
231
|
+
|
|
232
|
+
export default rhapsodic(
|
|
233
|
+
{
|
|
234
|
+
vue: true,
|
|
235
|
+
typescript: true
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
239
|
+
files: ['**/*.vue'],
|
|
240
|
+
rules: {
|
|
241
|
+
'vue/operator-linebreak': ['error', 'before'],
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
// Without `files`, they are general rules for all files
|
|
246
|
+
rules: {
|
|
247
|
+
'style/semi': ['error', 'never'],
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
We also provided the `overrides` options in each integration to make it easier:
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
// eslint.config.js
|
|
257
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
258
|
+
|
|
259
|
+
export default rhapsodic({
|
|
260
|
+
vue: {
|
|
261
|
+
overrides: {
|
|
262
|
+
'vue/operator-linebreak': ['error', 'before'],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
typescript: {
|
|
266
|
+
overrides: {
|
|
267
|
+
'ts/consistent-type-definitions': ['error', 'interface'],
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
yaml: {
|
|
271
|
+
overrides: {
|
|
272
|
+
// ...
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Config Composer
|
|
279
|
+
|
|
280
|
+
Since v2.10.0, the factory function `rhapsodic()` returns a [`FlatConfigComposer` object from `eslint-flat-config-utils`](https://github.com/rhapsodic/eslint-flat-config-utils#composer) where you can chain the methods to compose the config even more flexibly.
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
// eslint.config.js
|
|
284
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
285
|
+
|
|
286
|
+
export default rhapsodic()
|
|
287
|
+
.prepend(
|
|
288
|
+
// some configs before the main config
|
|
289
|
+
)
|
|
290
|
+
// overrides any named configs
|
|
291
|
+
.override(
|
|
292
|
+
'rhapsodic/stylistic/rules',
|
|
293
|
+
{
|
|
294
|
+
rules: {
|
|
295
|
+
'style/generator-star-spacing': ['error', { after: true, before: false }],
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
)
|
|
299
|
+
// rename plugin prefixes
|
|
300
|
+
.renamePlugins({
|
|
301
|
+
'old-prefix': 'new-prefix',
|
|
302
|
+
// ...
|
|
303
|
+
})
|
|
304
|
+
// ...
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Vue
|
|
308
|
+
|
|
309
|
+
Vue support is detected automatically by checking if `vue` is installed in your project. You can also explicitly enable/disable it:
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
// eslint.config.js
|
|
313
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
314
|
+
|
|
315
|
+
export default rhapsodic({
|
|
316
|
+
vue: true
|
|
317
|
+
})
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Vue Accessibility
|
|
321
|
+
|
|
322
|
+
To enable Vue accessibility support, you need to explicitly turn it on:
|
|
323
|
+
|
|
324
|
+
```js
|
|
325
|
+
// eslint.config.js
|
|
326
|
+
import rhapsodic from '@rhapsodic/eslint-config'
|
|
327
|
+
|
|
328
|
+
export default rhapsodic({
|
|
329
|
+
vue: {
|
|
330
|
+
a11y: true
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
pnpm i -D eslint-plugin-vuejs-accessibility
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Lint Staged
|
|
342
|
+
|
|
343
|
+
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
344
|
+
|
|
345
|
+
```json
|
|
346
|
+
{
|
|
347
|
+
"simple-git-hooks": {
|
|
348
|
+
"pre-commit": "pnpm lint-staged"
|
|
349
|
+
},
|
|
350
|
+
"lint-staged": {
|
|
351
|
+
"*": "eslint --fix"
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
and then
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
pnpm i -D lint-staged simple-git-hooks
|
|
360
|
+
|
|
361
|
+
// to active the hooks
|
|
362
|
+
npx simple-git-hooks
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## View what rules are enabled
|
|
366
|
+
|
|
367
|
+
I built a visual tool to help you view what rules are enabled in your project and apply them to what files, [@eslint/config-inspector](https://github.com/eslint/config-inspector)
|
|
368
|
+
|
|
369
|
+
Go to your project root that contains `eslint.config.js` and run:
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
npx @eslint/config-inspector
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Versioning Policy
|
|
376
|
+
|
|
377
|
+
This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.
|
|
378
|
+
|
|
379
|
+
### Changes Considered as Breaking Changes
|
|
380
|
+
|
|
381
|
+
- Node.js version requirement changes
|
|
382
|
+
- Huge refactors that might break the config
|
|
383
|
+
- Plugins made major changes that might break the config
|
|
384
|
+
- Changes that might affect most of the codebases
|
|
385
|
+
|
|
386
|
+
### Changes Considered as Non-breaking Changes
|
|
387
|
+
|
|
388
|
+
- Enable/disable rules and plugins (that might become stricter)
|
|
389
|
+
- Rules options changes
|
|
390
|
+
- Version bumps of dependencies
|
|
391
|
+
|
|
392
|
+
## License
|
|
393
|
+
|
|
394
|
+
[MIT](./LICENSE) License © 2025-PRESENT [Svyatoslav Fyodorov](https://github.com/intelrug)
|