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'
2
6
import {
3
7
command ,
4
8
comments ,
@@ -27,6 +31,7 @@ import {
27
31
import { hasUnocss , hasVue } from './env'
28
32
import type { ConfigNames } from './typegen'
29
33
import type { Config } from './types'
34
+ import type { Linter } from 'eslint'
30
35
31
36
/** Ignore common files and include javascript support */
32
37
export const presetJavaScript = ( ) : Config [ ] => [
@@ -75,30 +80,36 @@ export const presetAll = async (): Promise<Config[]> => [
75
80
...prettier ( ) ,
76
81
]
77
82
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
+
78
97
/** `@sxzz`'s preset. */
79
98
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 {
82
105
command : enableCommand = true ,
83
106
markdown : enableMarkdown = true ,
84
107
pnpm : enablePnpm = false ,
85
108
prettier : enablePrettier = true ,
86
109
unocss : enableUnocss = hasUnocss ( ) ,
87
110
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
+
102
113
const configs : Awaitable < Config [ ] > [ ] = [ presetBasic ( ) , yml ( ) , presetJsonc ( ) ]
103
114
if ( enableVue ) {
104
115
configs . push ( vue ( ) )
@@ -118,11 +129,11 @@ export function sxzz(
118
129
if ( enablePnpm ) {
119
130
configs . push ( pnpm ( ) )
120
131
}
121
- if ( Object . keys ( config ) . length > 0 ) {
122
- configs . push ( Array . isArray ( config ) ? config : [ config ] )
123
- }
124
132
configs . push ( specialCases ( ) )
125
133
126
- const composer = new FlatConfigComposer < Config , ConfigNames > ( ...configs )
134
+ const composer = new FlatConfigComposer < Config , ConfigNames > (
135
+ ...configs ,
136
+ ...( userConfigs as any ) ,
137
+ )
127
138
return composer
128
139
}
0 commit comments