From bc8afdd41a6d14afa4c03c37a12fd161b7cc278b Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 2 Aug 2024 14:53:07 +0200 Subject: [PATCH 1/2] fix(docs): mark eslint and typescript alias rules as implemented, --- tasks/lint_rules/package.json | 5 +- tasks/lint_rules/src/eslint-rules.cjs | 67 +++++++++++++++++++++++---- tasks/lint_rules/src/oxlint-rules.cjs | 18 ++++++- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/tasks/lint_rules/package.json b/tasks/lint_rules/package.json index 34f6650688ea3..09e6b11c97b61 100644 --- a/tasks/lint_rules/package.json +++ b/tasks/lint_rules/package.json @@ -12,9 +12,12 @@ "eslint-plugin-jsdoc": "latest", "eslint-plugin-jsx-a11y": "latest", "eslint-plugin-n": "latest", + "eslint-plugin-promise": "latest", "eslint-plugin-react": "latest", "eslint-plugin-react-hooks": "latest", "eslint-plugin-react-perf": "latest", - "eslint-plugin-unicorn": "latest" + "eslint-plugin-tree-shaking": "latest", + "eslint-plugin-unicorn": "latest", + "eslint-plugin-vitest": "latest" } } diff --git a/tasks/lint_rules/src/eslint-rules.cjs b/tasks/lint_rules/src/eslint-rules.cjs index 0ee0be1c51d59..94ff87b9a166a 100644 --- a/tasks/lint_rules/src/eslint-rules.cjs +++ b/tasks/lint_rules/src/eslint-rules.cjs @@ -56,19 +56,24 @@ const { } = require("eslint-plugin-react-perf"); // https://github.com/vercel/next.js/blob/canary/packages/eslint-plugin-next/src/index.ts const { rules: pluginNextAllRules } = require("@next/eslint-plugin-next"); +// https://github.com/eslint-community/eslint-plugin-promise/blob/main/index.js +const { + rules: pluginPromiseRules, + configs: pluginPromiseConfigs +} = require("eslint-plugin-promise"); +// https://github.com/veritem/eslint-plugin-vitest/blob/main/src/index.ts +const { + rules: pluginVitestRules, + configs: pluginVitestConfigs +} = require("eslint-plugin-vitest"); +// https://github.com/lukastaegert/eslint-plugin-tree-shaking/blob/master/src/index.ts +const { + rules: pluginTreeShakingRules, +} = require("eslint-plugin-tree-shaking"); /** @param {import("eslint").Linter} linter */ const loadPluginTypeScriptRules = (linter) => { - // We want to list all rules but not support type-checked rules - const pluginTypeScriptDisableTypeCheckedRules = new Map( - Object.entries(pluginTypeScriptConfigs["disable-type-checked"].rules), - ); for (const [name, rule] of Object.entries(pluginTypeScriptAllRules)) { - if ( - pluginTypeScriptDisableTypeCheckedRules.has(`@typescript-eslint/${name}`) - ) - continue; - const prefixedName = `typescript/${name}`; // Presented but type is `string | false` @@ -217,6 +222,44 @@ const loadPluginNextRules = (linter) => { } }; +/** @param {import("eslint").Linter} linter */ +const loadPluginPromiseRules = (linter) => { + const pluginPromiseReccommendedRules = new Map( + Object.entries(pluginPromiseConfigs.recommended.rules), + ); + for (const [name, rule] of Object.entries(pluginPromiseRules)) { + const prefixedName = `promise/${name}`; + + rule.meta.docs.recommended = + pluginPromiseReccommendedRules.has(prefixedName); + + linter.defineRule(prefixedName, rule); + } +} + +/** @param {import("eslint").Linter} linter */ +const loadPluginVitestRules = (linter) => { + const pluginVitestReccommendedRules = new Map( + Object.entries(pluginVitestConfigs.recommended.rules) + ); + for (const [name, rule] of Object.entries(pluginVitestRules)) { + const prefixedName = `vitest/${name}`; + + rule.meta.docs.recommended = pluginVitestReccommendedRules.has(prefixedName); + + linter.defineRule(prefixedName, rule); + } +} +/** @param {import("eslint").Linter} linter */ +const loadPluginTreeShakingRules = (linter) => { + for (const [name, rule] of Object.entries(pluginTreeShakingRules)) { + const prefixedName = `tree-shaking/${name}`; + + + linter.defineRule(prefixedName, rule); + } +} + /** * @typedef {{ * npm: string[]; @@ -242,6 +285,9 @@ exports.ALL_TARGET_PLUGINS = new Map([ ], ["react-perf", { npm: ["eslint-plugin-react-perf"], issueNo: 2041 }], ["nextjs", { npm: ["@next/eslint-plugin-next"], issueNo: 1929 }], + ["promise", { npm: ["eslint-plugin-promise"], issueNo: 9999 }], // TODO! + ["vitest", { npm: ["eslint-plugin-vitest"], issueNo: 9999 }], // TODO! + ["tree-shaking", { npm: ["eslint-plugin-tree-shaking"], issueNo: 9999 }], // TODO! ]); // All rules(including deprecated, recommended) are loaded initially. @@ -262,6 +308,9 @@ exports.loadTargetPluginRules = (linter) => { loadPluginReactRules(linter); loadPluginReactPerfRules(linter); loadPluginNextRules(linter); + loadPluginPromiseRules(linter); + loadPluginVitestRules(linter); + loadPluginTreeShakingRules(linter); }; // some typescript rules are some extension of the basic eslint rules diff --git a/tasks/lint_rules/src/oxlint-rules.cjs b/tasks/lint_rules/src/oxlint-rules.cjs index 829b57ab8efa5..ce7e0ef621bd2 100644 --- a/tasks/lint_rules/src/oxlint-rules.cjs +++ b/tasks/lint_rules/src/oxlint-rules.cjs @@ -2,6 +2,15 @@ const { resolve } = require("node:path"); const { readFile } = require("node:fs/promises"); const { pluginTypeScriptRulesNames } = require("./eslint-rules.cjs"); +/** + * Map OXC rules implementation + * @type {Map} + * */ +const MAP_SPECIFIC_RULES = new Map([ + // no-new-native-nonconstructor has already the testcase for eslint/no-new-symbol + ['eslint/no-new-native-nonconstructor', ['eslint/no-new-symbol']] +]); + const readAllImplementedRuleNames = async () => { const rulesFile = await readFile( resolve("crates/oxc_linter/src/rules.rs"), @@ -35,6 +44,8 @@ const readAllImplementedRuleNames = async () => { // Ignore no reference rules if (prefixedName.startsWith("oxc/")) continue; + rules.add(prefixedName); + // some tyescript rules are extensions of eslint core rules if (prefixedName.startsWith("eslint/")) { const ruleName = prefixedName.replace('eslint/', ''); @@ -42,11 +53,14 @@ const readAllImplementedRuleNames = async () => { // there is an alias, so we add it with this in mind. if (pluginTypeScriptRulesNames.includes(ruleName)) { rules.add(`typescript/${ruleName}`); - continue; } } + } - rules.add(prefixedName); + for (const [name, alias] of MAP_SPECIFIC_RULES) { + if (rules.has(name)) { + alias.forEach(aliasName => rules.add(aliasName)); + } } } From b129e7ce49b9c6127439db6adc2065c963c23437 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 2 Aug 2024 14:57:52 +0200 Subject: [PATCH 2/2] fix(docs): mark eslint and typescript alias rules as implemented --- tasks/lint_rules/src/eslint-rules.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/lint_rules/src/eslint-rules.cjs b/tasks/lint_rules/src/eslint-rules.cjs index 94ff87b9a166a..abdf90c29caa5 100644 --- a/tasks/lint_rules/src/eslint-rules.cjs +++ b/tasks/lint_rules/src/eslint-rules.cjs @@ -224,14 +224,14 @@ const loadPluginNextRules = (linter) => { /** @param {import("eslint").Linter} linter */ const loadPluginPromiseRules = (linter) => { - const pluginPromiseReccommendedRules = new Map( + const pluginPromiseRecommendedRules = new Map( Object.entries(pluginPromiseConfigs.recommended.rules), ); for (const [name, rule] of Object.entries(pluginPromiseRules)) { const prefixedName = `promise/${name}`; rule.meta.docs.recommended = - pluginPromiseReccommendedRules.has(prefixedName); + pluginPromiseRecommendedRules.has(prefixedName); linter.defineRule(prefixedName, rule); } @@ -239,13 +239,13 @@ const loadPluginPromiseRules = (linter) => { /** @param {import("eslint").Linter} linter */ const loadPluginVitestRules = (linter) => { - const pluginVitestReccommendedRules = new Map( + const pluginVitestRecommendedRules = new Map( Object.entries(pluginVitestConfigs.recommended.rules) ); for (const [name, rule] of Object.entries(pluginVitestRules)) { const prefixedName = `vitest/${name}`; - rule.meta.docs.recommended = pluginVitestReccommendedRules.has(prefixedName); + rule.meta.docs.recommended = pluginVitestRecommendedRules.has(prefixedName); linter.defineRule(prefixedName, rule); }