@kirklin/eslint-config 2.2.0 → 2.3.1
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 +134 -47
- package/README.zh-cn.md +175 -57
- package/dist/cli.cjs +56 -44
- package/dist/cli.js +72 -60
- package/dist/index.cjs +238 -80
- package/dist/index.d.cts +15295 -65
- package/dist/index.d.ts +15295 -65
- package/dist/index.js +238 -84
- package/package.json +45 -40
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), [Astro](#astro) 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,53 +45,46 @@
|
|
|
45
45
|
|
|
46
46
|
## Usage
|
|
47
47
|
|
|
48
|
-
### Wizard
|
|
48
|
+
### Starter Wizard
|
|
49
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.
|
|
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.
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
53
|
npx @kirklin/eslint-config@latest
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
### Install
|
|
56
|
+
### Manual Install
|
|
57
|
+
|
|
58
|
+
If you prefer to set up manually:
|
|
57
59
|
|
|
58
60
|
```bash
|
|
59
61
|
pnpm i -D eslint @kirklin/eslint-config
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
|
|
64
|
+
And create `eslint.config.mjs` in your project root:
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
|
-
// eslint.config.
|
|
67
|
+
// eslint.config.mjs
|
|
68
68
|
import kirklin from "@kirklin/eslint-config";
|
|
69
69
|
|
|
70
70
|
export default kirklin();
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
// eslint.config.js
|
|
77
|
-
const kirklin = require("@kirklin/eslint-config").default;
|
|
78
|
-
|
|
79
|
-
module.exports = kirklin();
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
> [!TIP]
|
|
83
|
-
> ESLint only detects `eslint.config.js` as the flat config entry, meaning you need to put `type: module` in your `package.json` or you have to use CJS in `eslint.config.js`. If you want explicit extension like `.mjs` or `.cjs`, or even `eslint.config.ts`, you can install [`eslint-ts-patch`](https://github.com/antfu/eslint-ts-patch) to fix it.
|
|
84
|
-
|
|
73
|
+
<details>
|
|
74
|
+
<summary>
|
|
85
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.
|
|
86
79
|
|
|
87
80
|
```js
|
|
88
|
-
// eslint.config.
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
// eslint.config.mjs
|
|
82
|
+
import kirklin from "@kirklin/eslint-config";
|
|
83
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
91
84
|
|
|
92
85
|
const compat = new FlatCompat();
|
|
93
86
|
|
|
94
|
-
|
|
87
|
+
export default kirklin(
|
|
95
88
|
{
|
|
96
89
|
ignores: [],
|
|
97
90
|
},
|
|
@@ -110,6 +103,8 @@ module.exports = kirklin(
|
|
|
110
103
|
|
|
111
104
|
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
112
105
|
|
|
106
|
+
</details>
|
|
107
|
+
|
|
113
108
|
### Add script for package.json
|
|
114
109
|
|
|
115
110
|
For example:
|
|
@@ -123,17 +118,7 @@ For example:
|
|
|
123
118
|
}
|
|
124
119
|
```
|
|
125
120
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
npx @kirklin/eslint-config@latest
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Before running the migration, make sure to commit your unsaved changes first.
|
|
135
|
-
|
|
136
|
-
## VS Code support (auto fix)
|
|
121
|
+
## VS Code support (auto fix on save)
|
|
137
122
|
|
|
138
123
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
139
124
|
|
|
@@ -180,7 +165,9 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
180
165
|
"json",
|
|
181
166
|
"jsonc",
|
|
182
167
|
"yaml",
|
|
183
|
-
"toml"
|
|
168
|
+
"toml",
|
|
169
|
+
"gql",
|
|
170
|
+
"graphql"
|
|
184
171
|
]
|
|
185
172
|
}
|
|
186
173
|
```
|
|
@@ -312,7 +299,7 @@ Since flat config requires us to explicitly provide the plugin names (instead of
|
|
|
312
299
|
|
|
313
300
|
| New Prefix | Original Prefix | Source Plugin |
|
|
314
301
|
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
315
|
-
| `import/*` | `
|
|
302
|
+
| `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
|
|
316
303
|
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
317
304
|
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
318
305
|
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
@@ -328,6 +315,17 @@ When you want to override rules, or disable them inline, you need to update to t
|
|
|
328
315
|
type foo = { bar: 2 }
|
|
329
316
|
```
|
|
330
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
|
+
|
|
331
329
|
### Rules Overrides
|
|
332
330
|
|
|
333
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:
|
|
@@ -357,7 +355,7 @@ export default kirklin(
|
|
|
357
355
|
);
|
|
358
356
|
```
|
|
359
357
|
|
|
360
|
-
We also provided
|
|
358
|
+
We also provided the `overrides` options in each integration to make it easier:
|
|
361
359
|
|
|
362
360
|
```js
|
|
363
361
|
// eslint.config.js
|
|
@@ -382,16 +380,72 @@ export default kirklin({
|
|
|
382
380
|
});
|
|
383
381
|
```
|
|
384
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
|
+
|
|
385
442
|
### Optional Configs
|
|
386
443
|
|
|
387
444
|
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
388
445
|
|
|
389
446
|
#### Formatters
|
|
390
447
|
|
|
391
|
-
|
|
392
|
-
> Experimental feature, changes might not follow semver.
|
|
393
|
-
|
|
394
|
-
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).
|
|
395
449
|
|
|
396
450
|
```js
|
|
397
451
|
// eslint.config.js
|
|
@@ -482,6 +536,25 @@ Running `npx eslint` should prompt you to install the required dependencies, oth
|
|
|
482
536
|
npm i -D eslint-plugin-astro
|
|
483
537
|
```
|
|
484
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
|
+
|
|
485
558
|
#### UnoCSS
|
|
486
559
|
|
|
487
560
|
To enable UnoCSS support, you need to explicitly turn it on:
|
|
@@ -507,9 +580,9 @@ This config also provides some optional plugins/rules for extended usage.
|
|
|
507
580
|
|
|
508
581
|
#### `perfectionist` (sorting)
|
|
509
582
|
|
|
510
|
-
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.
|
|
511
584
|
|
|
512
|
-
The plugin is installed but no rules are enabled by default.
|
|
585
|
+
The plugin is installed, but no rules are enabled by default.
|
|
513
586
|
|
|
514
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).
|
|
515
588
|
|
|
@@ -520,7 +593,6 @@ const objectWantedToSort = {
|
|
|
520
593
|
b: 1,
|
|
521
594
|
c: 3,
|
|
522
595
|
};
|
|
523
|
-
/* eslint perfectionist/sort-objects: "off" */
|
|
524
596
|
```
|
|
525
597
|
|
|
526
598
|
### Type Aware Rules
|
|
@@ -538,6 +610,21 @@ export default kirklin({
|
|
|
538
610
|
});
|
|
539
611
|
```
|
|
540
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
|
+
|
|
541
628
|
### Lint Staged
|
|
542
629
|
|
|
543
630
|
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
@@ -564,12 +651,12 @@ npx simple-git-hooks
|
|
|
564
651
|
|
|
565
652
|
## View what rules are enabled
|
|
566
653
|
|
|
567
|
-
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)
|
|
568
655
|
|
|
569
656
|
Go to your project root that contains `eslint.config.js` and run:
|
|
570
657
|
|
|
571
658
|
```bash
|
|
572
|
-
npx eslint
|
|
659
|
+
npx @eslint/config-inspector
|
|
573
660
|
```
|
|
574
661
|
|
|
575
662
|
## Versioning Policy
|