From 52c02c8d164de485dd3261cd7a87077f81a33e62 Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 28 Nov 2024 19:04:02 +0100 Subject: [PATCH] feat: support `overrides` in `buildFromOxlintConfig/File)` --- src/build-from-oxlint-config.ts | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/build-from-oxlint-config.ts b/src/build-from-oxlint-config.ts index 01c348c..0ab5945 100644 --- a/src/build-from-oxlint-config.ts +++ b/src/build-from-oxlint-config.ts @@ -20,13 +20,21 @@ type OxlintConfigCategories = Record; type OxlintConfigRules = Record; +type OxlintConfigOverride = { + files: string[]; + rules: OxlintConfigRules; +}; + type OxlintConfig = { [key: string]: unknown; plugins?: OxlintConfigPlugins; categories?: OxlintConfigCategories; rules?: OxlintConfigRules; + overrides: OxlintConfigOverride[]; }; +type EslintPluginOxLintConfig = Linter.Config>; + // default plugins, see const defaultPlugins: OxlintConfigPlugins = ['react', 'unicorn', 'typescript']; @@ -173,6 +181,12 @@ const handleRulesScope = ( } }; +const handleOverridesScope = ( + overrides: OxlintConfigOverride[] +): Linter.Config>[] => { + return []; +}; + /** * checks if value is validSet, or if validSet is an array, check if value is first value of it */ @@ -227,13 +241,21 @@ const readRulesFromConfig = ( : undefined; }; +const readOverridesFromConfig = ( + config: OxlintConfig +): OxlintConfigOverride[] | undefined => { + return 'overrides' in config && Array.isArray(config.overrides) + ? (config.overrides as OxlintConfigOverride[]) + : undefined; +}; + /** * builds turned off rules, which are supported by oxlint. * It accepts an object similar to the oxlint.json file. */ export const buildFromOxlintConfig = ( config: OxlintConfig -): Linter.Config>[] => { +): EslintPluginOxLintConfig[] => { const rules: Record = {}; const plugins = readPluginsFromConfig(config) ?? defaultPlugins; @@ -258,11 +280,19 @@ export const buildFromOxlintConfig = ( handleRulesScope(configRules, rules); } + const overrides = readOverridesFromConfig(config); + let subConfigs: EslintPluginOxLintConfig[] = []; + + if (overrides !== undefined) { + subConfigs = handleOverridesScope(config.overrides); + } + return [ { name: 'oxlint/from-oxlint-config', rules, }, + ...subConfigs, ]; }; @@ -275,7 +305,7 @@ export const buildFromOxlintConfig = ( */ export const buildFromOxlintConfigFile = ( oxlintConfigFile: string -): Linter.Config>[] => { +): EslintPluginOxLintConfig[] => { const config = getConfigContent(oxlintConfigFile); // we could not parse form the file, do not build with default values