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(docs): mark eslint and typescript alias rules as implemented, #4611

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion tasks/lint_rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
67 changes: 58 additions & 9 deletions tasks/lint_rules/src/eslint-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,24 @@
} = 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(
Copy link
Collaborator Author

@Sysix Sysix Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know why this rules were excluded. When I keep this line I get a warning:

👀 typescript/require-await is implemented but not found in their rules

Also this bumps the total rules:

There are 123(+ 26 deprecated) rules.

  • 41/75 recommended rules are remaining as TODO
  • 38/48 not recommended rules are remaining as TODO

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`
Expand Down Expand Up @@ -217,6 +222,44 @@
}
};

/** @param {import("eslint").Linter} linter */
const loadPluginPromiseRules = (linter) => {
const pluginPromiseReccommendedRules = new Map(

Check warning on line 227 in tasks/lint_rules/src/eslint-rules.cjs

View workflow job for this annotation

GitHub Actions / Spell Check

"Reccommended" should be "Recommended".
Object.entries(pluginPromiseConfigs.recommended.rules),
);
for (const [name, rule] of Object.entries(pluginPromiseRules)) {
const prefixedName = `promise/${name}`;

rule.meta.docs.recommended =
pluginPromiseReccommendedRules.has(prefixedName);

Check warning on line 234 in tasks/lint_rules/src/eslint-rules.cjs

View workflow job for this annotation

GitHub Actions / Spell Check

"Reccommended" should be "Recommended".

linter.defineRule(prefixedName, rule);
}
}

/** @param {import("eslint").Linter} linter */
const loadPluginVitestRules = (linter) => {
const pluginVitestReccommendedRules = new Map(

Check warning on line 242 in tasks/lint_rules/src/eslint-rules.cjs

View workflow job for this annotation

GitHub Actions / Spell Check

"Reccommended" should be "Recommended".
Object.entries(pluginVitestConfigs.recommended.rules)
);
for (const [name, rule] of Object.entries(pluginVitestRules)) {
const prefixedName = `vitest/${name}`;

rule.meta.docs.recommended = pluginVitestReccommendedRules.has(prefixedName);

Check warning on line 248 in tasks/lint_rules/src/eslint-rules.cjs

View workflow job for this annotation

GitHub Actions / Spell Check

"Reccommended" should be "Recommended".

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[];
Expand All @@ -242,6 +285,9 @@
],
["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!
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree-shaking has only one rule in node and in oxc.

You should know better if an Tracking-Issue should be created or not ;)

]);

// All rules(including deprecated, recommended) are loaded initially.
Expand All @@ -262,6 +308,9 @@
loadPluginReactRules(linter);
loadPluginReactPerfRules(linter);
loadPluginNextRules(linter);
loadPluginPromiseRules(linter);
loadPluginVitestRules(linter);
loadPluginTreeShakingRules(linter);
};

// some typescript rules are some extension of the basic eslint rules
Expand Down
18 changes: 16 additions & 2 deletions tasks/lint_rules/src/oxlint-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]>}
* */
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"),
Expand Down Expand Up @@ -35,18 +44,23 @@ 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/', '');

// 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));
}
}
}

Expand Down
Loading