UNPKG

@oxlint/migrate

Version:

Generates a `.oxlintrc.json` from a existing eslint flat config

60 lines (59 loc) 1.67 kB
import * as rules from "../../generated/rules.mjs"; import { nurseryRules } from "../../generated/rules.mjs"; const allRules = Object.values(rules).flat(); function replaceRuleDirectiveComment(comment, type, options) { const originalComment = comment; comment = comment.split(" -- ")[0].trimStart(); if (!comment.startsWith("eslint-")) { return originalComment; } comment = comment.substring(7); if (comment.startsWith("enable")) { comment = comment.substring(6); } else if (comment.startsWith("disable")) { comment = comment.substring(7); if (type === "Line") { if (comment.startsWith("-next-line")) { comment = comment.substring(10); } else if (comment.startsWith("-line")) { comment = comment.substring(5); } } } else { return originalComment; } if (!comment.startsWith(" ")) { return originalComment; } comment = comment.trimStart(); if (comment.length === 0) { return originalComment; } while (comment.length) { let foundRule = false; for (const rule of allRules) { if (comment.startsWith(rule)) { if (!options.withNursery && nurseryRules.includes(rule)) { continue; } foundRule = true; comment = comment.substring(rule.length).trimStart(); break; } } if (!foundRule) { return originalComment; } if (!comment.length) { break; } if (!comment.startsWith(", ")) { return originalComment; } comment = comment.substring(1).trimStart(); } return originalComment.replace(/eslint-/, "oxlint-"); } export { replaceRuleDirectiveComment as default };