Skip to content

Commit 89eb7f9

Browse files
committed
feat: support passing flat config to the first arg
1 parent deb5147 commit 89eb7f9

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/factory.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,21 @@ import {
2525
import type { OptionsConfig } from './types'
2626
import { combine } from './utils'
2727

28+
const flatConfigProps: (keyof FlatESLintConfigItem)[] = [
29+
'files',
30+
'ignores',
31+
'languageOptions',
32+
'linterOptions',
33+
'processor',
34+
'plugins',
35+
'rules',
36+
'settings',
37+
]
38+
2839
/**
2940
* Construct an array of ESLint flat config items.
3041
*/
31-
export function coderwyd(options: OptionsConfig = {}, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]) {
42+
export function coderwyd(options: OptionsConfig & FlatESLintConfigItem = {}, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]) {
3243
const isInEditor = options.isInEditor ?? !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE) && !process.env.CI)
3344

3445
const enableVue = options.vue ?? (isPackageExists('vue') || isPackageExists('nuxt') || isPackageExists('vitepress') || isPackageExists('@slidev/cli'))
@@ -96,6 +107,16 @@ export function coderwyd(options: OptionsConfig = {}, ...userConfigs: (FlatESLin
96107
if (options.markdown ?? true)
97108
configs.push(markdown({ componentExts }))
98109

110+
// User can optionally pass a flat config item to the first argument
111+
// We pick the known keys as ESLint would do schema validation
112+
const fusedConfig = flatConfigProps.reduce((acc, key) => {
113+
if (key in options)
114+
acc[key] = options[key]
115+
return acc
116+
}, {} as FlatESLintConfigItem)
117+
if (Object.keys(fusedConfig).length)
118+
configs.push([fusedConfig])
119+
99120
return combine(
100121
...configs,
101122
...userConfigs,

0 commit comments

Comments
 (0)