From ce925b4603f419f21baf68d452885a6f6034d6c2 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 23 Sep 2023 15:11:27 +0800 Subject: [PATCH] feat: support passing flat config to the first arg --- src/factory.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/factory.ts b/src/factory.ts index 62cb8d95e5..4c1786b2da 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -24,10 +24,21 @@ import { import type { OptionsConfig } from './types' import { combine } from './utils' +const flatConfigProps: (keyof FlatESLintConfigItem)[] = [ + 'files', + 'ignores', + 'languageOptions', + 'linterOptions', + 'processor', + 'plugins', + 'rules', + 'settings', +] + /** * Construct an array of ESLint flat config items. */ -export function antfu(options: OptionsConfig = {}, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]) { +export function antfu(options: OptionsConfig & FlatESLintConfigItem = {}, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]) { const isInEditor = options.isInEditor ?? !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE) && !process.env.CI) const enableVue = options.vue ?? (isPackageExists('vue') || isPackageExists('nuxt') || isPackageExists('vitepress') || isPackageExists('@slidev/cli')) const enableTypeScript = options.typescript ?? (isPackageExists('typescript')) @@ -85,6 +96,16 @@ export function antfu(options: OptionsConfig = {}, ...userConfigs: (FlatESLintCo if (options.markdown ?? true) configs.push(markdown({ componentExts })) + // User can optionally pass a flat config item to the first argument + // We pick the known keys as ESLint would do schema validation + const fusedConfig = flatConfigProps.reduce((acc, key) => { + if (key in options) + acc[key] = options[key] + return acc + }, {} as FlatESLintConfigItem) + if (Object.keys(fusedConfig).length) + configs.push([fusedConfig]) + return combine( ...configs, ...userConfigs,