@kirklin/eslint-config 2.1.0 → 2.3.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/README.md +158 -44
- package/README.zh-cn.md +175 -57
- package/dist/cli.cjs +469 -146
- package/dist/cli.js +470 -147
- package/dist/index.cjs +389 -96
- package/dist/index.d.cts +15328 -62
- package/dist/index.d.ts +15328 -62
- package/dist/index.js +387 -100
- package/package.json +74 -49
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
37
37
|
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
38
38
|
- Respects `.gitignore` by default
|
|
39
|
-
- Optional [React](#react), [Svelte](#svelte), [UnoCSS](#unocss) support
|
|
39
|
+
- Optional [React](#react), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Solid](#solid) support
|
|
40
40
|
- Optional [formatters](#formatters) support for CSS, HTML, etc.
|
|
41
41
|
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
42
42
|
|
|
@@ -45,45 +45,46 @@
|
|
|
45
45
|
|
|
46
46
|
## Usage
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Starter Wizard
|
|
49
|
+
|
|
50
|
+
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.
|
|
49
51
|
|
|
50
52
|
```bash
|
|
51
|
-
|
|
53
|
+
npx @kirklin/eslint-config@latest
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
###
|
|
55
|
-
|
|
56
|
-
With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
|
|
56
|
+
### Manual Install
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
// eslint.config.js
|
|
60
|
-
import kirklin from "@kirklin/eslint-config";
|
|
58
|
+
If you prefer to set up manually:
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
```bash
|
|
61
|
+
pnpm i -D eslint @kirklin/eslint-config
|
|
63
62
|
```
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
And create `eslint.config.mjs` in your project root:
|
|
66
65
|
|
|
67
66
|
```js
|
|
68
|
-
// eslint.config.
|
|
69
|
-
|
|
67
|
+
// eslint.config.mjs
|
|
68
|
+
import kirklin from "@kirklin/eslint-config";
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
export default kirklin();
|
|
72
71
|
```
|
|
73
72
|
|
|
74
|
-
>
|
|
75
|
-
>
|
|
76
|
-
|
|
73
|
+
<details>
|
|
74
|
+
<summary>
|
|
77
75
|
Combined with legacy config:
|
|
76
|
+
</summary>
|
|
77
|
+
|
|
78
|
+
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.
|
|
78
79
|
|
|
79
80
|
```js
|
|
80
|
-
// eslint.config.
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// eslint.config.mjs
|
|
82
|
+
import kirklin from "@kirklin/eslint-config";
|
|
83
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
83
84
|
|
|
84
85
|
const compat = new FlatCompat();
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
export default kirklin(
|
|
87
88
|
{
|
|
88
89
|
ignores: [],
|
|
89
90
|
},
|
|
@@ -102,6 +103,8 @@ module.exports = kirklin(
|
|
|
102
103
|
|
|
103
104
|
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
104
105
|
|
|
106
|
+
</details>
|
|
107
|
+
|
|
105
108
|
### Add script for package.json
|
|
106
109
|
|
|
107
110
|
For example:
|
|
@@ -115,17 +118,7 @@ For example:
|
|
|
115
118
|
}
|
|
116
119
|
```
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npx @kirklin/eslint-config@latest
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Before running the migration, make sure to commit your unsaved changes first.
|
|
127
|
-
|
|
128
|
-
## VS Code support (auto fix)
|
|
121
|
+
## VS Code support (auto fix on save)
|
|
129
122
|
|
|
130
123
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
131
124
|
|
|
@@ -172,7 +165,9 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
172
165
|
"json",
|
|
173
166
|
"jsonc",
|
|
174
167
|
"yaml",
|
|
175
|
-
"toml"
|
|
168
|
+
"toml",
|
|
169
|
+
"gql",
|
|
170
|
+
"graphql"
|
|
176
171
|
]
|
|
177
172
|
}
|
|
178
173
|
```
|
|
@@ -304,7 +299,7 @@ Since flat config requires us to explicitly provide the plugin names (instead of
|
|
|
304
299
|
|
|
305
300
|
| New Prefix | Original Prefix | Source Plugin |
|
|
306
301
|
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
307
|
-
| `import/*` | `
|
|
302
|
+
| `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
|
|
308
303
|
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
309
304
|
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
310
305
|
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
@@ -320,6 +315,17 @@ When you want to override rules, or disable them inline, you need to update to t
|
|
|
320
315
|
type foo = { bar: 2 }
|
|
321
316
|
```
|
|
322
317
|
|
|
318
|
+
> [!NOTE]
|
|
319
|
+
> About plugin renaming - it is actually rather a dangrous move that might leading to potential naming collisions, pointed out [here](https://github.com/eslint/eslint/discussions/17766) and [here](https://github.com/prettier/eslint-config-prettier#eslintconfigjs-flat-config-plugin-caveat). As this config also very **personal** and **opinionated**, I ambitiously position this config as the only **"top-level"** config per project, that might pivots the taste of how rules are named.
|
|
320
|
+
>
|
|
321
|
+
> This config cares more about the user-facings DX, and try to ease out the implementation details. For example, users could keep using the semantic `import/order` without ever knowing the underlying plugin has migrated twice to `eslint-plugin-i` and then to `eslint-plugin-import-x`. User are also not forced to migrate to the implicit `i/order` halfway only because we swapped the implementation to a fork.
|
|
322
|
+
>
|
|
323
|
+
> That said, it's probably still not a good idea. You might not want to doing this if you are maintaining your own eslint config.
|
|
324
|
+
>
|
|
325
|
+
> Feel free to open issues if you want to combine this config with some other config presets but faced naming collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the renaming.
|
|
326
|
+
|
|
327
|
+
Since v2.9.0, this preset will automatically rename the plugins also for your custom configs. You can use the original prefix to override the rules directly.
|
|
328
|
+
|
|
323
329
|
### Rules Overrides
|
|
324
330
|
|
|
325
331
|
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:
|
|
@@ -349,7 +355,7 @@ export default kirklin(
|
|
|
349
355
|
);
|
|
350
356
|
```
|
|
351
357
|
|
|
352
|
-
We also provided
|
|
358
|
+
We also provided the `overrides` options in each integration to make it easier:
|
|
353
359
|
|
|
354
360
|
```js
|
|
355
361
|
// eslint.config.js
|
|
@@ -374,16 +380,72 @@ export default kirklin({
|
|
|
374
380
|
});
|
|
375
381
|
```
|
|
376
382
|
|
|
383
|
+
### Config Composer
|
|
384
|
+
|
|
385
|
+
Since v2.10.0, the factory function `kirklin()` returns a [`FlatConfigComposer` object from `eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer) where you can chain the methods to compose the config even more flexibly.
|
|
386
|
+
|
|
387
|
+
```js
|
|
388
|
+
// eslint.config.js
|
|
389
|
+
import kirklin from "@kirklin/eslint-config";
|
|
390
|
+
|
|
391
|
+
export default kirklin()
|
|
392
|
+
.prepend(
|
|
393
|
+
// some configs before the main config
|
|
394
|
+
)
|
|
395
|
+
// overrides any named configs
|
|
396
|
+
.override(
|
|
397
|
+
"kirklin/imports",
|
|
398
|
+
{
|
|
399
|
+
rules: {
|
|
400
|
+
"import/order": ["error", { "newlines-between": "always" }],
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
)
|
|
404
|
+
// rename plugin prefixes
|
|
405
|
+
.renamePlugins({
|
|
406
|
+
"old-prefix": "new-prefix",
|
|
407
|
+
// ...
|
|
408
|
+
});
|
|
409
|
+
// ...
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Vue
|
|
413
|
+
|
|
414
|
+
Vue support is detected automatically by checking if `vue` is installed in your project. You can also explicitly enable/disable it:
|
|
415
|
+
|
|
416
|
+
```js
|
|
417
|
+
// eslint.config.js
|
|
418
|
+
import kirklin from "@kirklin/eslint-config";
|
|
419
|
+
|
|
420
|
+
export default kirklin({
|
|
421
|
+
vue: true
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### Vue 2
|
|
426
|
+
|
|
427
|
+
We have limited support for Vue 2 (as it's already [reached EOL](https://v2.vuejs.org/eol/)). If you are still using Vue 2, you can configure it manually by setting `vueVersion` to `2`:
|
|
428
|
+
|
|
429
|
+
```js
|
|
430
|
+
// eslint.config.js
|
|
431
|
+
import kirklin from "@kirklin/eslint-config";
|
|
432
|
+
|
|
433
|
+
export default kirklin({
|
|
434
|
+
vue: {
|
|
435
|
+
vueVersion: 2
|
|
436
|
+
},
|
|
437
|
+
});
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
As it's in maintenance mode, we only accept bug fixes for Vue 2. It might also be removed in the future when `eslint-plugin-vue` drops support for Vue 2. We recommend upgrading to Vue 3 if possible.
|
|
441
|
+
|
|
377
442
|
### Optional Configs
|
|
378
443
|
|
|
379
444
|
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
380
445
|
|
|
381
446
|
#### Formatters
|
|
382
447
|
|
|
383
|
-
|
|
384
|
-
> Experimental feature, changes might not follow semver.
|
|
385
|
-
|
|
386
|
-
Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/kirklin/eslint-plugin-format).
|
|
448
|
+
Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
|
|
387
449
|
|
|
388
450
|
```js
|
|
389
451
|
// eslint.config.js
|
|
@@ -455,6 +517,44 @@ Running `npx eslint` should prompt you to install the required dependencies, oth
|
|
|
455
517
|
npm i -D eslint-plugin-svelte
|
|
456
518
|
```
|
|
457
519
|
|
|
520
|
+
#### Astro
|
|
521
|
+
|
|
522
|
+
To enable astro support, you need to explicitly turn it on:
|
|
523
|
+
|
|
524
|
+
```js
|
|
525
|
+
// eslint.config.js
|
|
526
|
+
import kirklin from "@kirklin/eslint-config";
|
|
527
|
+
|
|
528
|
+
export default kirklin({
|
|
529
|
+
astro: true,
|
|
530
|
+
});
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
534
|
+
|
|
535
|
+
```bash
|
|
536
|
+
npm i -D eslint-plugin-astro
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
#### Solid
|
|
540
|
+
|
|
541
|
+
To enable Solid support, you need to explicitly turn it on:
|
|
542
|
+
|
|
543
|
+
```js
|
|
544
|
+
// eslint.config.js
|
|
545
|
+
import kirklin from "@kirklin/eslint-config";
|
|
546
|
+
|
|
547
|
+
export default kirklin({
|
|
548
|
+
solid: true,
|
|
549
|
+
});
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
553
|
+
|
|
554
|
+
```bash
|
|
555
|
+
npm i -D eslint-plugin-solid
|
|
556
|
+
```
|
|
557
|
+
|
|
458
558
|
#### UnoCSS
|
|
459
559
|
|
|
460
560
|
To enable UnoCSS support, you need to explicitly turn it on:
|
|
@@ -480,9 +580,9 @@ This config also provides some optional plugins/rules for extended usage.
|
|
|
480
580
|
|
|
481
581
|
#### `perfectionist` (sorting)
|
|
482
582
|
|
|
483
|
-
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to
|
|
583
|
+
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sort object keys, imports, etc, with auto-fix.
|
|
484
584
|
|
|
485
|
-
The plugin is installed but no rules are enabled by default.
|
|
585
|
+
The plugin is installed, but no rules are enabled by default.
|
|
486
586
|
|
|
487
587
|
It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
|
|
488
588
|
|
|
@@ -493,7 +593,6 @@ const objectWantedToSort = {
|
|
|
493
593
|
b: 1,
|
|
494
594
|
c: 3,
|
|
495
595
|
};
|
|
496
|
-
/* eslint perfectionist/sort-objects: "off" */
|
|
497
596
|
```
|
|
498
597
|
|
|
499
598
|
### Type Aware Rules
|
|
@@ -511,6 +610,21 @@ export default kirklin({
|
|
|
511
610
|
});
|
|
512
611
|
```
|
|
513
612
|
|
|
613
|
+
### Editor Specific Disables
|
|
614
|
+
|
|
615
|
+
Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
|
|
616
|
+
|
|
617
|
+
This is to prevent unused imports from getting removed by the IDE during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them:
|
|
618
|
+
|
|
619
|
+
```js
|
|
620
|
+
// eslint.config.js
|
|
621
|
+
import kirklin from "@kirklin/eslint-config";
|
|
622
|
+
|
|
623
|
+
export default kirklin({
|
|
624
|
+
isInEditor: false
|
|
625
|
+
});
|
|
626
|
+
```
|
|
627
|
+
|
|
514
628
|
### Lint Staged
|
|
515
629
|
|
|
516
630
|
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
@@ -537,12 +651,12 @@ npx simple-git-hooks
|
|
|
537
651
|
|
|
538
652
|
## View what rules are enabled
|
|
539
653
|
|
|
540
|
-
I built a visual tool to help you view what rules are enabled in your project and apply them to what files, [eslint
|
|
654
|
+
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)
|
|
541
655
|
|
|
542
656
|
Go to your project root that contains `eslint.config.js` and run:
|
|
543
657
|
|
|
544
658
|
```bash
|
|
545
|
-
npx eslint
|
|
659
|
+
npx @eslint/config-inspector
|
|
546
660
|
```
|
|
547
661
|
|
|
548
662
|
## Versioning Policy
|