From 2290e2c5cec6351b41c82360e893b31a1732402e Mon Sep 17 00:00:00 2001 From: Sysix Date: Wed, 4 Dec 2024 18:52:45 +0100 Subject: [PATCH] feat: support overrides in buildFromOxlintConfig(File) --- src/build-from-oxlint-config.spec.ts | 6 +++--- src/build-from-oxlint-config/index.ts | 2 +- src/build-from-oxlint-config/overrides.ts | 3 +-- src/build-from-oxlint-config/rules.ts | 11 ++--------- src/build-from-oxlint-config/types.ts | 4 +--- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/build-from-oxlint-config.spec.ts b/src/build-from-oxlint-config.spec.ts index 28b8f9d..f53b10a 100644 --- a/src/build-from-oxlint-config.spec.ts +++ b/src/build-from-oxlint-config.spec.ts @@ -235,7 +235,7 @@ describe('buildFromOxlintConfig', () => { expect('vitest/no-conditional-tests' in configs[1].rules).toBe(true); }); - it('reenable rule in overrides', () => { + it(' rule in overrides', () => { const configs = buildFromOxlintConfig({ rules: { 'no-debugger': 'warn', @@ -252,11 +252,11 @@ describe('buildFromOxlintConfig', () => { expect(configs.length).toBe(2); assert(configs[0].rules !== undefined); - expect(configs[0].rules['no-debugger']).toBe('off'); + expect('no-debugger' in configs[0].rules).toBe(true); console.log(configs[1].rules); assert(configs[1].rules !== undefined); - expect(configs[1].rules['no-debugger']).toBe('warn'); + expect('no-debugger' in configs[1].rules).toBe(false); }); }); }); diff --git a/src/build-from-oxlint-config/index.ts b/src/build-from-oxlint-config/index.ts index 4ed9643..3ce6f29 100644 --- a/src/build-from-oxlint-config/index.ts +++ b/src/build-from-oxlint-config/index.ts @@ -83,7 +83,7 @@ export const buildFromOxlintConfig = ( const configRules = readRulesFromConfig(config); if (configRules !== undefined) { - handleRulesScope(configRules, rules, true); + handleRulesScope(configRules, rules); } const overrides = readOverridesFromConfig(config); diff --git a/src/build-from-oxlint-config/overrides.ts b/src/build-from-oxlint-config/overrides.ts index ea65fa5..e2d04c4 100644 --- a/src/build-from-oxlint-config/overrides.ts +++ b/src/build-from-oxlint-config/overrides.ts @@ -30,8 +30,7 @@ export const handleOverridesScope = ( const rules = readRulesFromConfig(override); if (rules !== undefined) { - // ToDo -- when off, we should enable the default settings - handleRulesScope(rules, eslintRules, false); + handleRulesScope(rules, eslintRules); } eslintConfig.rules = eslintRules; diff --git a/src/build-from-oxlint-config/rules.ts b/src/build-from-oxlint-config/rules.ts index 1041347..ae8661b 100644 --- a/src/build-from-oxlint-config/rules.ts +++ b/src/build-from-oxlint-config/rules.ts @@ -77,8 +77,7 @@ const isActiveValue = (value: unknown) => */ export const handleRulesScope = ( oxlintRules: OxlintConfigRules, - rules: Record, - disableRule: boolean + rules: Record ): void => { for (const rule in oxlintRules) { const eslintName = getEsLintRuleName(rule); @@ -95,13 +94,7 @@ export const handleRulesScope = ( rules[eslintName] = 'off'; } else if (rule in rules && isDeactivateValue(oxlintRules[rule])) { // rules extended by categories or plugins can be disabled manually - if (disableRule) { - delete rules[eslintName]; - } - // inside overrides we need to enable the rule again - else { - rules[eslintName] = 'warn'; - } + delete rules[eslintName]; } } }; diff --git a/src/build-from-oxlint-config/types.ts b/src/build-from-oxlint-config/types.ts index 74083bb..c5f07c2 100644 --- a/src/build-from-oxlint-config/types.ts +++ b/src/build-from-oxlint-config/types.ts @@ -12,9 +12,7 @@ export type OxlintConfigOverride = { rules?: OxlintConfigRules; }; -export type EslintPluginOxLintConfig = Linter.Config< - Record ->; +export type EslintPluginOxLintConfig = Linter.Config>; export type OxlintConfig = { [key: string]: unknown;