oxc/tasks/lint_rules/src/main.cjs
Yuji Sugiura cba8a4c131
feat(tasks): Enable tasks/lint_rules(JS ver) (#2177)
- [x] Remove old task(Rust ver)
- [x] Migrate to new task(JS ver)
- [x] Confirm CI works w/o `--output`
-
https://github.com/oxc-project/oxc/actions/runs/7663961642/job/20887579432?pr=2177
- [x] Confirm CI works w/ fake issue no
  - https://github.com/oxc-project/oxc/issues/2117
- [x] Enable

- - -

I've noticed that

- eslint/no-extra-semi
- eslint/no-mixed-spaces-and-tabs

are maked as deprecated and also recommended.

This is ESLint side
[issue](https://github.com/eslint/eslint/pull/17696#issuecomment-1792452766)
and will fix after v9.
2024-01-26 15:45:05 +08:00

83 lines
2.3 KiB
JavaScript

const { parseArgs } = require("node:util");
const {
ALL_TARGET_PLUGINS,
createESLintLinter,
loadTargetPluginRules,
} = require("./eslint-rules.cjs");
const {
createRuleEntries,
updateNotSupportedStatus,
updateImplementedStatus,
} = require("./oxlint-rules.cjs");
const { renderMarkdown } = require("./markdown-renderer.cjs");
const { updateGitHubIssue } = require("./result-reporter.cjs");
const HELP = `
Usage:
$ cmd [--target=<pluginName>]... [--update] [--help]
Options:
--target, -t: Which plugin to target, multiple allowed
--update: Update the issue instead of printing to stdout
--help, -h: Print this help message
Plugins: ${Array.from(ALL_TARGET_PLUGINS.keys()).join(", ")}
`;
(async () => {
//
// Parse arguments
//
const { values } = parseArgs({
options: {
// Mainly for debugging
target: { type: "string", short: "t", multiple: true },
update: { type: "boolean" },
help: { type: "boolean", short: "h" },
},
});
if (values.help) return console.log(HELP);
const targetPluginNames = new Set(values.target ?? ALL_TARGET_PLUGINS.keys());
for (const pluginName of targetPluginNames) {
if (!ALL_TARGET_PLUGINS.has(pluginName)) {
console.error(`Unknown plugin name: ${pluginName}`);
return;
}
}
//
// Load linter and all plugins
//
const linter = createESLintLinter();
loadTargetPluginRules(linter);
//
// Generate entry and update status
//
const ruleEntries = createRuleEntries(linter.getRules());
await updateImplementedStatus(ruleEntries);
updateNotSupportedStatus(ruleEntries);
//
// Render list and update if necessary
//
const results = await Promise.allSettled(
Array.from(targetPluginNames).map((pluginName) => {
const pluginMeta =
/** @type {import("./eslint-rules.cjs").TargetPluginMeta} */ (
ALL_TARGET_PLUGINS.get(pluginName)
);
const content = renderMarkdown(pluginName, pluginMeta, ruleEntries);
if (!values.update) return Promise.resolve(content);
// Requires `env.GITHUB_TOKEN`
return updateGitHubIssue(pluginMeta, content);
}),
);
for (const result of results) {
if (result.status === "fulfilled") console.log(result.value);
if (result.status === "rejected") console.error(result.reason);
}
})();