Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tasks/lint_rules): Integrate react and react-hooks rules #3315

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions tasks/lint_rules/src/eslint-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ const loadPluginReactRules = (linter) => {

linter.defineRule(prefixedName, rule);
}
};

/** @param {import("eslint").Linter} linter */
const loadPluginReactHooksRules = (linter) => {
// `react-hooks` plugin is available along with `react` plugin
for (const [name, rule] of Object.entries(pluginReactHooksAllRules)) {
const prefixedName = `react-hooks/${name}`;
// This may be conflict with `react` plugin
// (but `react-hooks` plugin has only 2 rules, so it's fine...!)
const prefixedName = `react/${name}`;

// @ts-expect-error: The types of 'meta.type', 'string' is not assignable to type '"problem" | "suggestion" | "layout" | undefined'.
linter.defineRule(prefixedName, rule);
Expand Down Expand Up @@ -219,24 +219,29 @@ const loadPluginNextRules = (linter) => {

/**
* @typedef {{
* npm: string;
* npm: string[];
* issueNo: number;
* }} TargetPluginMeta
* @type {Map<string, TargetPluginMeta>}
*/
exports.ALL_TARGET_PLUGINS = new Map([
["eslint", { npm: "eslint", issueNo: 479 }],
["typescript", { npm: "@typescript-eslint/eslint-plugin", issueNo: 2180 }],
["n", { npm: "eslint-plugin-n", issueNo: 493 }],
["unicorn", { npm: "eslint-plugin-unicorn", issueNo: 684 }],
["jsdoc", { npm: "eslint-plugin-jsdoc", issueNo: 1170 }],
["import", { npm: "eslint-plugin-import", issueNo: 1117 }],
["jsx-a11y", { npm: "eslint-plugin-jsx-a11y", issueNo: 1141 }],
["jest", { npm: "eslint-plugin-jest", issueNo: 492 }],
["react", { npm: "eslint-plugin-react", issueNo: 1022 }],
["react-hooks", { npm: "eslint-plugin-react-hooks", issueNo: 2174 }],
["react-perf", { npm: "eslint-plugin-react-perf", issueNo: 2041 }],
["nextjs", { npm: "@next/eslint-plugin-next", issueNo: 1929 }],
["eslint", { npm: ["eslint"], issueNo: 479 }],
["typescript", { npm: ["@typescript-eslint/eslint-plugin"], issueNo: 2180 }],
["n", { npm: ["eslint-plugin-n"], issueNo: 493 }],
["unicorn", { npm: ["eslint-plugin-unicorn"], issueNo: 684 }],
["jsdoc", { npm: ["eslint-plugin-jsdoc"], issueNo: 1170 }],
["import", { npm: ["eslint-plugin-import"], issueNo: 1117 }],
["jsx-a11y", { npm: ["eslint-plugin-jsx-a11y"], issueNo: 1141 }],
["jest", { npm: ["eslint-plugin-jest"], issueNo: 492 }],
[
"react",
{
npm: ["eslint-plugin-react", "eslint-plugin-react-hooks"],
issueNo: 1022,
},
],
["react-perf", { npm: ["eslint-plugin-react-perf"], issueNo: 2041 }],
["nextjs", { npm: ["@next/eslint-plugin-next"], issueNo: 1929 }],
]);

// All rules(including deprecated, recommended) are loaded initially.
Expand All @@ -255,7 +260,6 @@ exports.loadTargetPluginRules = (linter) => {
loadPluginJSXA11yRules(linter);
loadPluginJestRules(linter);
loadPluginReactRules(linter);
loadPluginReactHooksRules(linter);
loadPluginReactPerfRules(linter);
loadPluginNextRules(linter);
};
4 changes: 2 additions & 2 deletions tasks/lint_rules/src/markdown-renderer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @typedef {{ isImplemented: number; isNotSupported: number; total: number }} CounterView
*/

/** @param {{ npm: string; }} props */
/** @param {{ npm: string[]; }} props */
const renderIntroduction = ({ npm }) => `
> [!WARNING]
> This comment is maintained by CI. Do not edit this comment directly.
> To update comment template, see https://github.com/oxc-project/oxc/tree/main/tasks/lint_rules

This is tracking issue for \`${npm}\`.
This is tracking issue for ${npm.map(n => "`" + n + "`").join(", ")}.
`;

/**
Expand Down