@oxlint/migrate
Version:
Generates a `.oxlintrc.json` from a existing eslint flat config
79 lines (78 loc) • 2.77 kB
JavaScript
import { transformEnvAndGlobals, detectEnvironmentByGlobals } from "./env_globals.mjs";
import { cleanUpOxlintConfig } from "./cleanup.mjs";
import { transformIgnorePatterns } from "./ignorePatterns.mjs";
import { transformRuleEntry, detectNeededRulesPlugins } from "./plugins_rules.mjs";
import { detectSameOverride } from "./overrides.mjs";
const buildConfig = (configs, oxlintConfig, options) => {
if (oxlintConfig === void 0) {
if (options?.merge) {
oxlintConfig = {
// disable all plugins and check later
plugins: ["oxc", "typescript", "unicorn", "react"],
categories: {
correctness: "warn"
}
};
} else {
oxlintConfig = {
$schema: "./node_modules/oxlint/configuration_schema.json",
// disable all plugins and check later
plugins: [],
categories: {
// ToDo: for merge set the default category manuel when it is not found
// ToDo: later we can remove it again
// default category
correctness: "off"
}
};
}
}
if (oxlintConfig.$schema === void 0 && options?.merge) {
oxlintConfig.$schema = "./node_modules/oxlint/configuration_schema.json";
}
if (oxlintConfig.env?.builtin === void 0) {
if (oxlintConfig.env === void 0) {
oxlintConfig.env = {};
}
oxlintConfig.env.builtin = true;
}
const overrides = options?.merge ? oxlintConfig.overrides ?? [] : [];
for (const config of configs) {
if (config.name?.startsWith("oxlint/")) {
continue;
}
let targetConfig;
if (config.files === void 0) {
targetConfig = oxlintConfig;
} else {
targetConfig = {
files: Array.isArray(config.files) ? config.files : [config.files]
};
const [push, result] = detectSameOverride(oxlintConfig, targetConfig);
if (push) {
overrides.push(result);
}
}
if (config.settings !== void 0) ;
transformIgnorePatterns(config, targetConfig, options);
transformRuleEntry(config, targetConfig, options);
transformEnvAndGlobals(config, targetConfig, options);
if ("files" in targetConfig) {
detectNeededRulesPlugins(targetConfig, options);
detectEnvironmentByGlobals(targetConfig);
cleanUpOxlintConfig(targetConfig);
}
}
oxlintConfig.overrides = overrides;
detectNeededRulesPlugins(oxlintConfig, options);
detectEnvironmentByGlobals(oxlintConfig);
cleanUpOxlintConfig(oxlintConfig);
return oxlintConfig;
};
const main = async (configs, oxlintConfig, options) => {
const resolved = await Promise.resolve(configs);
return Array.isArray(resolved) ? buildConfig(resolved, oxlintConfig, options) : buildConfig([resolved], oxlintConfig, options);
};
export {
main as default
};