Skip to content

Commit 2613d04

Browse files
committedMar 9, 2025··
feat!: move options to first param, userConfigs to second
1 parent 19a34cd commit 2613d04

File tree

4 files changed

+52
-41
lines changed

4 files changed

+52
-41
lines changed
 

‎README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ Require Node.js >= 18.18, and ESLint >= 9.5.0.
2727
```js
2828
import { sxzz } from '@sxzz/eslint-config'
2929
export default sxzz(
30-
[
31-
/* your custom config */
32-
],
3330
// Features: it'll detect installed dependency and enable necessary features automatically
3431
{
3532
prettier: true,
3633
markdown: true,
3734
vue: true, // auto detection
3835
unocss: false, // auto detection
3936
},
40-
)
37+
[
38+
/* your custom config */
39+
],
40+
).removeRules('foo/bar') // see more in https://github.com/antfu/eslint-flat-config-utils
4141
```
4242

4343
### Presets

‎eslint-inspector.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { sxzz } from './src/index.ts'
22

3-
export default sxzz([], {
3+
export default sxzz({
44
vue: true,
55
unocss: true,
66
pnpm: true,

‎eslint.config.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { sxzz } from './src/index'
22

3-
export default sxzz(
4-
[
5-
{
6-
files: ['src/**/*.ts'],
7-
rules: {
8-
'perfectionist/sort-objects': 'error',
9-
},
3+
export default sxzz({
4+
vue: true,
5+
pnpm: true,
6+
}).append(
7+
{
8+
files: ['src/**/*.ts'],
9+
rules: {
10+
'perfectionist/sort-objects': 'error',
1011
},
11-
{
12-
files: ['**/*.md/*'],
13-
rules: {
14-
'perfectionist/sort-imports': 'off',
15-
'perfectionist/sort-named-imports': 'off',
16-
},
12+
},
13+
{
14+
files: ['**/*.md/*'],
15+
rules: {
16+
'perfectionist/sort-imports': 'off',
17+
'perfectionist/sort-named-imports': 'off',
1718
},
18-
],
19-
{ vue: true, pnpm: true },
19+
},
2020
)

‎src/presets.ts

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { FlatConfigComposer, type Awaitable } from 'eslint-flat-config-utils'
1+
import {
2+
FlatConfigComposer,
3+
type Arrayable,
4+
type Awaitable,
5+
} from 'eslint-flat-config-utils'
26
import {
37
command,
48
comments,
@@ -27,6 +31,7 @@ import {
2731
import { hasUnocss, hasVue } from './env'
2832
import type { ConfigNames } from './typegen'
2933
import type { Config } from './types'
34+
import type { Linter } from 'eslint'
3035

3136
/** Ignore common files and include javascript support */
3237
export const presetJavaScript = (): Config[] => [
@@ -75,30 +80,36 @@ export const presetAll = async (): Promise<Config[]> => [
7580
...prettier(),
7681
]
7782

83+
export interface Options {
84+
/** Vue support. Auto-enable if detected. */
85+
vue?: boolean
86+
/** Prettier support. Default: true */
87+
prettier?: boolean
88+
/** markdown support. Default: true */
89+
markdown?: boolean
90+
/** UnoCSS support. Auto-enable if detected. */
91+
unocss?: boolean
92+
sortKeys?: boolean
93+
command?: boolean
94+
pnpm?: boolean
95+
}
96+
7897
/** `@sxzz`'s preset. */
7998
export function sxzz(
80-
config: Config | Config[] = [],
81-
{
99+
options: Options = {},
100+
...userConfigs: Awaitable<
101+
Arrayable<Config> | FlatConfigComposer<any, any> | Linter.Config[]
102+
>[]
103+
): FlatConfigComposer<Config, ConfigNames> {
104+
const {
82105
command: enableCommand = true,
83106
markdown: enableMarkdown = true,
84107
pnpm: enablePnpm = false,
85108
prettier: enablePrettier = true,
86109
unocss: enableUnocss = hasUnocss(),
87110
vue: enableVue = hasVue(),
88-
}: Partial<{
89-
/** Vue support. Auto-enable if detected. */
90-
vue: boolean
91-
/** Prettier support. Default: true */
92-
prettier: boolean
93-
/** markdown support. Default: true */
94-
markdown: boolean
95-
/** UnoCSS support. Auto-enable if detected. */
96-
unocss: boolean
97-
sortKeys: boolean
98-
command: boolean
99-
pnpm: boolean
100-
}> = {},
101-
): FlatConfigComposer<Config, ConfigNames> {
111+
} = options
112+
102113
const configs: Awaitable<Config[]>[] = [presetBasic(), yml(), presetJsonc()]
103114
if (enableVue) {
104115
configs.push(vue())
@@ -118,11 +129,11 @@ export function sxzz(
118129
if (enablePnpm) {
119130
configs.push(pnpm())
120131
}
121-
if (Object.keys(config).length > 0) {
122-
configs.push(Array.isArray(config) ? config : [config])
123-
}
124132
configs.push(specialCases())
125133

126-
const composer = new FlatConfigComposer<Config, ConfigNames>(...configs)
134+
const composer = new FlatConfigComposer<Config, ConfigNames>(
135+
...configs,
136+
...(userConfigs as any),
137+
)
127138
return composer
128139
}

0 commit comments

Comments
 (0)
Please sign in to comment.