@antfu/eslint-config 2.9.1 → 2.10.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 +50 -24
- package/dist/cli.cjs +2 -1
- package/dist/cli.js +2 -1
- package/dist/index.cjs +8 -5
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -5
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -21,53 +21,46 @@
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
### Wizard
|
|
24
|
+
### Starter Wizard
|
|
25
25
|
|
|
26
|
-
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config.
|
|
26
|
+
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.
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
npx @antfu/eslint-config@latest
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
### Install
|
|
32
|
+
### Manual Install
|
|
33
|
+
|
|
34
|
+
If you prefer to set up manually:
|
|
33
35
|
|
|
34
36
|
```bash
|
|
35
37
|
pnpm i -D eslint @antfu/eslint-config
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
|
|
40
|
+
And create `eslint.config.mjs` in your project root:
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
|
-
// eslint.config.
|
|
43
|
+
// eslint.config.mjs
|
|
44
44
|
import antfu from '@antfu/eslint-config'
|
|
45
45
|
|
|
46
46
|
export default antfu()
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
// eslint.config.js
|
|
53
|
-
const antfu = require('@antfu/eslint-config').default
|
|
54
|
-
|
|
55
|
-
module.exports = antfu()
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
> [!TIP]
|
|
59
|
-
> 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.
|
|
60
|
-
|
|
49
|
+
<details>
|
|
50
|
+
<summary>
|
|
61
51
|
Combined with legacy config:
|
|
52
|
+
</summary>
|
|
53
|
+
|
|
54
|
+
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.
|
|
62
55
|
|
|
63
56
|
```js
|
|
64
|
-
// eslint.config.
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
// eslint.config.mjs
|
|
58
|
+
import antfu from '@antfu/eslint-config'
|
|
59
|
+
import { FlatCompat } from '@eslint/eslintrc'
|
|
67
60
|
|
|
68
61
|
const compat = new FlatCompat()
|
|
69
62
|
|
|
70
|
-
|
|
63
|
+
export default antfu(
|
|
71
64
|
{
|
|
72
65
|
ignores: [],
|
|
73
66
|
},
|
|
@@ -86,6 +79,8 @@ module.exports = antfu(
|
|
|
86
79
|
|
|
87
80
|
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
88
81
|
|
|
82
|
+
</details>
|
|
83
|
+
|
|
89
84
|
### Add script for package.json
|
|
90
85
|
|
|
91
86
|
For example:
|
|
@@ -99,7 +94,7 @@ For example:
|
|
|
99
94
|
}
|
|
100
95
|
```
|
|
101
96
|
|
|
102
|
-
## VS Code support (auto fix)
|
|
97
|
+
## VS Code support (auto fix on save)
|
|
103
98
|
|
|
104
99
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
105
100
|
|
|
@@ -305,6 +300,8 @@ type foo = { bar: 2 }
|
|
|
305
300
|
>
|
|
306
301
|
> 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.
|
|
307
302
|
|
|
303
|
+
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.
|
|
304
|
+
|
|
308
305
|
### Rules Overrides
|
|
309
306
|
|
|
310
307
|
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:
|
|
@@ -359,6 +356,35 @@ export default antfu({
|
|
|
359
356
|
})
|
|
360
357
|
```
|
|
361
358
|
|
|
359
|
+
### Pipeline
|
|
360
|
+
|
|
361
|
+
Since v2.10.0, the factory function `antfu()` returns a [pipeline object from `eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#pipe) where you can chain the methods to compose the config even more flexibly.
|
|
362
|
+
|
|
363
|
+
```js
|
|
364
|
+
// eslint.config.js
|
|
365
|
+
import antfu from '@antfu/eslint-config'
|
|
366
|
+
|
|
367
|
+
export default antfu()
|
|
368
|
+
.prepend(
|
|
369
|
+
// some configs before the main config
|
|
370
|
+
)
|
|
371
|
+
// overrides any named configs
|
|
372
|
+
.override(
|
|
373
|
+
'antfu:imports',
|
|
374
|
+
{
|
|
375
|
+
rules: {
|
|
376
|
+
'import/order': ['error', { 'newlines-between': 'always' }],
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
)
|
|
380
|
+
// rename plugin prefixes
|
|
381
|
+
.renamePlugins({
|
|
382
|
+
'old-prefix': 'new-prefix',
|
|
383
|
+
// ...
|
|
384
|
+
})
|
|
385
|
+
// ...
|
|
386
|
+
```
|
|
387
|
+
|
|
362
388
|
### Optional Configs
|
|
363
389
|
|
|
364
390
|
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
package/dist/cli.cjs
CHANGED
|
@@ -48,7 +48,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
48
48
|
var package_default = {
|
|
49
49
|
name: "@antfu/eslint-config",
|
|
50
50
|
type: "module",
|
|
51
|
-
version: "2.
|
|
51
|
+
version: "2.10.0",
|
|
52
52
|
packageManager: "pnpm@8.15.5",
|
|
53
53
|
description: "Anthony's ESLint config",
|
|
54
54
|
author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
@@ -143,6 +143,7 @@ var package_default = {
|
|
|
143
143
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
144
144
|
"@typescript-eslint/parser": "^7.4.0",
|
|
145
145
|
"eslint-config-flat-gitignore": "^0.1.3",
|
|
146
|
+
"eslint-flat-config-utils": "0.0.4",
|
|
146
147
|
"eslint-merge-processors": "^0.1.0",
|
|
147
148
|
"eslint-plugin-antfu": "^2.1.2",
|
|
148
149
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import c from "picocolors";
|
|
|
19
19
|
var package_default = {
|
|
20
20
|
name: "@antfu/eslint-config",
|
|
21
21
|
type: "module",
|
|
22
|
-
version: "2.
|
|
22
|
+
version: "2.10.0",
|
|
23
23
|
packageManager: "pnpm@8.15.5",
|
|
24
24
|
description: "Anthony's ESLint config",
|
|
25
25
|
author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
@@ -114,6 +114,7 @@ var package_default = {
|
|
|
114
114
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
115
115
|
"@typescript-eslint/parser": "^7.4.0",
|
|
116
116
|
"eslint-config-flat-gitignore": "^0.1.3",
|
|
117
|
+
"eslint-flat-config-utils": "0.0.4",
|
|
117
118
|
"eslint-merge-processors": "^0.1.0",
|
|
118
119
|
"eslint-plugin-antfu": "^2.1.2",
|
|
119
120
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
100
100
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
101
101
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
102
102
|
var import_local_pkg4 = require("local-pkg");
|
|
103
|
+
var import_eslint_flat_config_utils = require("eslint-flat-config-utils");
|
|
103
104
|
|
|
104
105
|
// src/plugins.ts
|
|
105
106
|
var import_eslint_plugin_antfu = __toESM(require("eslint-plugin-antfu"), 1);
|
|
@@ -2101,7 +2102,7 @@ var defaultPluginRenaming = {
|
|
|
2101
2102
|
"vitest": "test",
|
|
2102
2103
|
"yml": "yaml"
|
|
2103
2104
|
};
|
|
2104
|
-
|
|
2105
|
+
function antfu(options = {}, ...userConfigs) {
|
|
2105
2106
|
const {
|
|
2106
2107
|
astro: enableAstro = false,
|
|
2107
2108
|
autoRenamePlugins = true,
|
|
@@ -2243,13 +2244,15 @@ async function antfu(options = {}, ...userConfigs) {
|
|
|
2243
2244
|
}, {});
|
|
2244
2245
|
if (Object.keys(fusedConfig).length)
|
|
2245
2246
|
configs.push([fusedConfig]);
|
|
2246
|
-
|
|
2247
|
+
let pipeline = new import_eslint_flat_config_utils.FlatConfigPipeline();
|
|
2248
|
+
pipeline = pipeline.append(
|
|
2247
2249
|
...configs,
|
|
2248
2250
|
...userConfigs
|
|
2249
2251
|
);
|
|
2250
|
-
if (autoRenamePlugins)
|
|
2251
|
-
|
|
2252
|
-
|
|
2252
|
+
if (autoRenamePlugins) {
|
|
2253
|
+
pipeline = pipeline.renamePlugins(defaultPluginRenaming);
|
|
2254
|
+
}
|
|
2255
|
+
return pipeline;
|
|
2253
2256
|
}
|
|
2254
2257
|
function resolveSubOptions(options, key) {
|
|
2255
2258
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlatConfigPipeline } from 'eslint-flat-config-utils';
|
|
1
2
|
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
2
3
|
import { ParserOptions } from '@typescript-eslint/parser';
|
|
3
4
|
import { Options } from 'eslint-processor-vue-blocks';
|
|
@@ -432,7 +433,7 @@ declare const defaultPluginRenaming: {
|
|
|
432
433
|
* @returns {Promise<UserConfigItem[]>}
|
|
433
434
|
* The merged ESLint configurations.
|
|
434
435
|
*/
|
|
435
|
-
declare function antfu(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]):
|
|
436
|
+
declare function antfu(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): FlatConfigPipeline<UserConfigItem>;
|
|
436
437
|
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
437
438
|
declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
|
|
438
439
|
declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlatConfigPipeline } from 'eslint-flat-config-utils';
|
|
1
2
|
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
2
3
|
import { ParserOptions } from '@typescript-eslint/parser';
|
|
3
4
|
import { Options } from 'eslint-processor-vue-blocks';
|
|
@@ -432,7 +433,7 @@ declare const defaultPluginRenaming: {
|
|
|
432
433
|
* @returns {Promise<UserConfigItem[]>}
|
|
433
434
|
* The merged ESLint configurations.
|
|
434
435
|
*/
|
|
435
|
-
declare function antfu(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]):
|
|
436
|
+
declare function antfu(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): FlatConfigPipeline<UserConfigItem>;
|
|
436
437
|
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
437
438
|
declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
|
|
438
439
|
declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): any;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import process3 from "process";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { isPackageExists as isPackageExists4 } from "local-pkg";
|
|
5
|
+
import { FlatConfigPipeline } from "eslint-flat-config-utils";
|
|
5
6
|
|
|
6
7
|
// src/plugins.ts
|
|
7
8
|
import { default as default2 } from "eslint-plugin-antfu";
|
|
@@ -2003,7 +2004,7 @@ var defaultPluginRenaming = {
|
|
|
2003
2004
|
"vitest": "test",
|
|
2004
2005
|
"yml": "yaml"
|
|
2005
2006
|
};
|
|
2006
|
-
|
|
2007
|
+
function antfu(options = {}, ...userConfigs) {
|
|
2007
2008
|
const {
|
|
2008
2009
|
astro: enableAstro = false,
|
|
2009
2010
|
autoRenamePlugins = true,
|
|
@@ -2145,13 +2146,15 @@ async function antfu(options = {}, ...userConfigs) {
|
|
|
2145
2146
|
}, {});
|
|
2146
2147
|
if (Object.keys(fusedConfig).length)
|
|
2147
2148
|
configs.push([fusedConfig]);
|
|
2148
|
-
|
|
2149
|
+
let pipeline = new FlatConfigPipeline();
|
|
2150
|
+
pipeline = pipeline.append(
|
|
2149
2151
|
...configs,
|
|
2150
2152
|
...userConfigs
|
|
2151
2153
|
);
|
|
2152
|
-
if (autoRenamePlugins)
|
|
2153
|
-
|
|
2154
|
-
|
|
2154
|
+
if (autoRenamePlugins) {
|
|
2155
|
+
pipeline = pipeline.renamePlugins(defaultPluginRenaming);
|
|
2156
|
+
}
|
|
2157
|
+
return pipeline;
|
|
2155
2158
|
}
|
|
2156
2159
|
function resolveSubOptions(options, key) {
|
|
2157
2160
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antfu/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.10.0",
|
|
5
5
|
"packageManager": "pnpm@8.15.5",
|
|
6
6
|
"description": "Anthony's ESLint config",
|
|
7
7
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
85
85
|
"@typescript-eslint/parser": "^7.4.0",
|
|
86
86
|
"eslint-config-flat-gitignore": "^0.1.3",
|
|
87
|
+
"eslint-flat-config-utils": "0.0.4",
|
|
87
88
|
"eslint-merge-processors": "^0.1.0",
|
|
88
89
|
"eslint-plugin-antfu": "^2.1.2",
|
|
89
90
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
@@ -146,7 +147,7 @@
|
|
|
146
147
|
"typescript": "^5.4.3",
|
|
147
148
|
"vitest": "^1.4.0",
|
|
148
149
|
"vue": "^3.4.21",
|
|
149
|
-
"@antfu/eslint-config": "2.
|
|
150
|
+
"@antfu/eslint-config": "2.10.0"
|
|
150
151
|
},
|
|
151
152
|
"simple-git-hooks": {
|
|
152
153
|
"pre-commit": "pnpm lint-staged"
|