Skip to content

Commit

Permalink
feat: support overrides in buildFromOxlintConfig(File)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Dec 4, 2024
1 parent 6728fb9 commit 2290e2c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/build-from-oxlint-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/build-from-oxlint-config/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 2 additions & 9 deletions src/build-from-oxlint-config/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ const isActiveValue = (value: unknown) =>
*/
export const handleRulesScope = (
oxlintRules: OxlintConfigRules,
rules: Record<string, 'off' | 'warn'>,
disableRule: boolean
rules: Record<string, 'off'>
): void => {
for (const rule in oxlintRules) {
const eslintName = getEsLintRuleName(rule);
Expand All @@ -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];
}
}
};
Expand Down
4 changes: 1 addition & 3 deletions src/build-from-oxlint-config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export type OxlintConfigOverride = {
rules?: OxlintConfigRules;
};

export type EslintPluginOxLintConfig = Linter.Config<
Record<string, 'off' | 'warn'>
>;
export type EslintPluginOxLintConfig = Linter.Config<Record<string, 'off'>>;

export type OxlintConfig = {
[key: string]: unknown;
Expand Down

0 comments on commit 2290e2c

Please sign in to comment.