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 Nov 28, 2024
1 parent 10ed50a commit febb33a
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ type OxlintConfigCategories = Record<string, unknown>;
type OxlintConfigRules = Record<string, unknown>;

type OxlintConfigOverride = {
files: string[];
rules: OxlintConfigRules;
files?: string[];
rules?: OxlintConfigRules;
};

type OxlintConfig = {
[key: string]: unknown;
plugins?: OxlintConfigPlugins;
categories?: OxlintConfigCategories;
rules?: OxlintConfigRules;
overrides: OxlintConfigOverride[];
overrides?: OxlintConfigOverride[];
};

type EslintPluginOxLintConfig = Linter.Config<Record<string, 'off'>>;
Expand Down Expand Up @@ -182,9 +182,28 @@ const handleRulesScope = (
};

const handleOverridesScope = (
overrides: OxlintConfigOverride[]
): Linter.Config<Record<string, 'off'>>[] => {
return [];
overrides: OxlintConfigOverride[],
configs: EslintPluginOxLintConfig[]
): void => {
for (const overrideIndex in overrides) {
const override = overrides[overrideIndex];
const eslintConfig: EslintPluginOxLintConfig = {
name: `oxlint/from-oxlint-config-override-${overrideIndex}`,
};

// expect that oxlint `files` syntax is the same as eslint
if ('files' in override) {
eslintConfig.files = override.files;
}

if (isObject(override.rules)) {
const rules: Record<string, 'off'> = {};
handleRulesScope(override.rules!, rules);
eslintConfig.rules = rules;
}

configs.push(eslintConfig);
}
};

/**
Expand Down Expand Up @@ -281,19 +300,18 @@ export const buildFromOxlintConfig = (
}

const overrides = readOverridesFromConfig(config);
let subConfigs: EslintPluginOxLintConfig[] = [];

if (overrides !== undefined) {
subConfigs = handleOverridesScope(config.overrides);
}

return [
const configs: EslintPluginOxLintConfig[] = [
{
name: 'oxlint/from-oxlint-config',
rules,
},
...subConfigs,
];

if (overrides !== undefined) {
handleOverridesScope(overrides, configs);
}

return configs;
};

/**
Expand Down

0 comments on commit febb33a

Please sign in to comment.