Skip to content

Commit d33ba66

Browse files
committedMar 26, 2024
feat: support flat config pipeline
1 parent 8768a6f commit d33ba66

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed
 

‎README.md

+31
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ type foo = { bar: 2 }
300300
>
301301
> 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.
302302
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+
303305
### Rules Overrides
304306

305307
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:
@@ -354,6 +356,35 @@ export default antfu({
354356
})
355357
```
356358

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+
357388
### Optional Configs
358389

359390
We provide some optional configs for specific use cases, that we don't include their dependencies by default.

‎eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
import styleMigrate from '@stylistic/eslint-plugin-migrate'
23
import JITI from 'jiti'
34

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"@typescript-eslint/eslint-plugin": "^7.4.0",
9797
"@typescript-eslint/parser": "^7.4.0",
9898
"eslint-config-flat-gitignore": "^0.1.3",
99+
"eslint-flat-config-utils": "0.0.4",
99100
"eslint-merge-processors": "^0.1.0",
100101
"eslint-plugin-antfu": "^2.1.2",
101102
"eslint-plugin-eslint-comments": "^3.2.0",

‎pnpm-lock.yaml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/factory.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import process from 'node:process'
22
import fs from 'node:fs'
33
import { isPackageExists } from 'local-pkg'
4+
import { FlatConfigPipeline } from 'eslint-flat-config-utils'
45
import type { Awaitable, FlatConfigItem, OptionsConfig, UserConfigItem } from './types'
56
import {
67
astro,
@@ -26,7 +27,7 @@ import {
2627
vue,
2728
yaml,
2829
} from './configs'
29-
import { combine, interopDefault, renamePluginInConfigs } from './utils'
30+
import { interopDefault } from './utils'
3031
import { formatters } from './configs/formatters'
3132

3233
const flatConfigProps: (keyof FlatConfigItem)[] = [
@@ -67,10 +68,10 @@ export const defaultPluginRenaming = {
6768
* @returns {Promise<UserConfigItem[]>}
6869
* The merged ESLint configurations.
6970
*/
70-
export async function antfu(
71+
export function antfu(
7172
options: OptionsConfig & FlatConfigItem = {},
7273
...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]
73-
): Promise<UserConfigItem[]> {
74+
): FlatConfigPipeline<UserConfigItem> {
7475
const {
7576
astro: enableAstro = false,
7677
autoRenamePlugins = true,
@@ -242,15 +243,20 @@ export async function antfu(
242243
if (Object.keys(fusedConfig).length)
243244
configs.push([fusedConfig])
244245

245-
const merged = await combine(
246-
...configs,
247-
...userConfigs,
248-
)
246+
let pipeline = new FlatConfigPipeline<UserConfigItem>()
247+
248+
pipeline = pipeline
249+
.append(
250+
...configs,
251+
...userConfigs,
252+
)
249253

250-
if (autoRenamePlugins)
251-
return renamePluginInConfigs(merged, defaultPluginRenaming)
254+
if (autoRenamePlugins) {
255+
pipeline = pipeline
256+
.renamePlugins(defaultPluginRenaming)
257+
}
252258

253-
return merged
259+
return pipeline
254260
}
255261

256262
export type ResolvedOptions<T> = T extends boolean

0 commit comments

Comments
 (0)
Please sign in to comment.