mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(tasks): Add more plugins for tasks/lint_rules2 (#2167)
Part pf #2020 - [x] jsx-a11y - [x] react, react-hooks, react-perf - [x] nextjs Now, we can track all target plugins(AFAIK)? 🕵🏻
This commit is contained in:
parent
989ab88bc6
commit
83a54e0d06
3 changed files with 102 additions and 2 deletions
|
|
@ -7,12 +7,17 @@
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@next/eslint-plugin-next": "latest",
|
||||||
"@typescript-eslint/eslint-plugin": "latest",
|
"@typescript-eslint/eslint-plugin": "latest",
|
||||||
"eslint": "latest",
|
"eslint": "latest",
|
||||||
"eslint-plugin-import": "latest",
|
"eslint-plugin-import": "latest",
|
||||||
"eslint-plugin-jest": "latest",
|
"eslint-plugin-jest": "latest",
|
||||||
"eslint-plugin-jsdoc": "latest",
|
"eslint-plugin-jsdoc": "latest",
|
||||||
|
"eslint-plugin-jsx-a11y": "latest",
|
||||||
"eslint-plugin-n": "latest",
|
"eslint-plugin-n": "latest",
|
||||||
|
"eslint-plugin-react": "latest",
|
||||||
|
"eslint-plugin-react-hooks": "latest",
|
||||||
|
"eslint-plugin-react-perf": "latest",
|
||||||
"eslint-plugin-unicorn": "latest"
|
"eslint-plugin-unicorn": "latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ const { Linter } = require("eslint");
|
||||||
// Even worse, every plugin has slightly different types, different way of configuration in detail...
|
// Even worse, every plugin has slightly different types, different way of configuration in detail...
|
||||||
//
|
//
|
||||||
// So here, we need to list all rules while normalizing recommended and deprecated flags.
|
// So here, we need to list all rules while normalizing recommended and deprecated flags.
|
||||||
// - rule.meta.docs.recommended
|
|
||||||
// - rule.meta.deprecated
|
// - rule.meta.deprecated
|
||||||
|
// - rule.meta.docs.recommended
|
||||||
|
// Some plugins have the recommended flag in rule itself, but some plugins have it in config.
|
||||||
|
|
||||||
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/index.ts
|
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/index.ts
|
||||||
const {
|
const {
|
||||||
|
|
@ -32,8 +33,26 @@ const {
|
||||||
rules: pluginImportAllRules,
|
rules: pluginImportAllRules,
|
||||||
configs: pluginImportConfigs,
|
configs: pluginImportConfigs,
|
||||||
} = require("eslint-plugin-import");
|
} = require("eslint-plugin-import");
|
||||||
|
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/index.js
|
||||||
|
const {
|
||||||
|
rules: pluginJSXA11yAllRules,
|
||||||
|
configs: pluginJSXA11yConfigs,
|
||||||
|
} = require("eslint-plugin-jsx-a11y");
|
||||||
// https://github.com/jest-community/eslint-plugin-jest/blob/main/src/index.ts
|
// https://github.com/jest-community/eslint-plugin-jest/blob/main/src/index.ts
|
||||||
const { rules: pluginJestAllRules } = require("eslint-plugin-jest");
|
const { rules: pluginJestAllRules } = require("eslint-plugin-jest");
|
||||||
|
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/index.js
|
||||||
|
const { rules: pluginReactAllRules } = require("eslint-plugin-react");
|
||||||
|
// https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/index.js
|
||||||
|
const {
|
||||||
|
rules: pluginReactHooksAllRules,
|
||||||
|
} = require("eslint-plugin-react-hooks");
|
||||||
|
// https://github.com/cvazac/eslint-plugin-react-perf/blob/master/index.js
|
||||||
|
const {
|
||||||
|
rules: pluginReactPerfAllRules,
|
||||||
|
configs: pluginReactPerfConfigs,
|
||||||
|
} = 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");
|
||||||
|
|
||||||
// All rules(including deprecated, recommended) are loaded initially.
|
// All rules(including deprecated, recommended) are loaded initially.
|
||||||
exports.createESLintLinter = () => new Linter();
|
exports.createESLintLinter = () => new Linter();
|
||||||
|
|
@ -116,6 +135,25 @@ exports.loadPluginImportRules = (linter) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @param {import("eslint").Linter} linter */
|
||||||
|
exports.loadPluginJSXA11yRules = (linter) => {
|
||||||
|
const pluginJSXA11yRecommendedRules = new Map(
|
||||||
|
Object.entries(pluginJSXA11yConfigs.recommended.rules),
|
||||||
|
);
|
||||||
|
for (const [name, rule] of Object.entries(pluginJSXA11yAllRules)) {
|
||||||
|
const prefixedName = `jsx-a11y/${name}`;
|
||||||
|
|
||||||
|
const recommendedValue = pluginJSXA11yRecommendedRules.get(prefixedName);
|
||||||
|
rule.meta.docs.recommended =
|
||||||
|
recommendedValue &&
|
||||||
|
// Type is `string | [string, opt]`
|
||||||
|
recommendedValue !== "off" &&
|
||||||
|
recommendedValue[0] !== "off";
|
||||||
|
|
||||||
|
linter.defineRule(prefixedName, rule);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** @param {import("eslint").Linter} linter */
|
/** @param {import("eslint").Linter} linter */
|
||||||
exports.loadPluginJestRules = (linter) => {
|
exports.loadPluginJestRules = (linter) => {
|
||||||
for (const [name, rule] of Object.entries(pluginJestAllRules)) {
|
for (const [name, rule] of Object.entries(pluginJestAllRules)) {
|
||||||
|
|
@ -127,3 +165,46 @@ exports.loadPluginJestRules = (linter) => {
|
||||||
linter.defineRule(prefixedName, rule);
|
linter.defineRule(prefixedName, rule);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @param {import("eslint").Linter} linter */
|
||||||
|
exports.loadPluginReactRules = (linter) => {
|
||||||
|
for (const [name, rule] of Object.entries(pluginReactAllRules)) {
|
||||||
|
const prefixedName = `react/${name}`;
|
||||||
|
|
||||||
|
linter.defineRule(prefixedName, rule);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @param {import("eslint").Linter} linter */
|
||||||
|
exports.loadPluginReactHooksRules = (linter) => {
|
||||||
|
for (const [name, rule] of Object.entries(pluginReactHooksAllRules)) {
|
||||||
|
const prefixedName = `react-hooks/${name}`;
|
||||||
|
|
||||||
|
// @ts-expect-error: The types of 'meta.type', 'string' is not assignable to type '"problem" | "suggestion" | "layout" | undefined'.
|
||||||
|
linter.defineRule(prefixedName, rule);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @param {import("eslint").Linter} linter */
|
||||||
|
exports.loadPluginReactPerfRules = (linter) => {
|
||||||
|
const pluginReactPerfRecommendedRules = new Map(
|
||||||
|
Object.entries(pluginReactPerfConfigs.recommended.rules),
|
||||||
|
);
|
||||||
|
for (const [name, rule] of Object.entries(pluginReactPerfAllRules)) {
|
||||||
|
const prefixedName = `react-perf/${name}`;
|
||||||
|
|
||||||
|
rule.meta.docs.recommended =
|
||||||
|
pluginReactPerfRecommendedRules.has(prefixedName);
|
||||||
|
|
||||||
|
linter.defineRule(prefixedName, rule);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @param {import("eslint").Linter} linter */
|
||||||
|
exports.loadPluginNextRules = (linter) => {
|
||||||
|
for (const [name, rule] of Object.entries(pluginNextAllRules)) {
|
||||||
|
const prefixedName = `nextjs/${name}`;
|
||||||
|
|
||||||
|
linter.defineRule(prefixedName, rule);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@ const {
|
||||||
loadPluginUnicornRules,
|
loadPluginUnicornRules,
|
||||||
loadPluginJSDocRules,
|
loadPluginJSDocRules,
|
||||||
loadPluginImportRules,
|
loadPluginImportRules,
|
||||||
|
loadPluginJSXA11yRules,
|
||||||
loadPluginJestRules,
|
loadPluginJestRules,
|
||||||
|
loadPluginReactRules,
|
||||||
|
loadPluginReactHooksRules,
|
||||||
|
loadPluginReactPerfRules,
|
||||||
|
loadPluginNextRules,
|
||||||
} = require("./eslint-rules.cjs");
|
} = require("./eslint-rules.cjs");
|
||||||
const {
|
const {
|
||||||
createRuleEntries,
|
createRuleEntries,
|
||||||
|
|
@ -23,7 +28,12 @@ const ALL_TARGET_PLUGIN_NAMES = new Set([
|
||||||
"unicorn",
|
"unicorn",
|
||||||
"jsdoc",
|
"jsdoc",
|
||||||
"import",
|
"import",
|
||||||
|
"jsx-a11y",
|
||||||
"jest",
|
"jest",
|
||||||
|
"react",
|
||||||
|
"react-hooks",
|
||||||
|
"react-perf",
|
||||||
|
"nextjs",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const HELP = `
|
const HELP = `
|
||||||
|
|
@ -67,8 +77,12 @@ Plugins: ${[...ALL_TARGET_PLUGIN_NAMES].join(", ")}
|
||||||
loadPluginUnicornRules(linter);
|
loadPluginUnicornRules(linter);
|
||||||
loadPluginJSDocRules(linter);
|
loadPluginJSDocRules(linter);
|
||||||
loadPluginImportRules(linter);
|
loadPluginImportRules(linter);
|
||||||
|
loadPluginJSXA11yRules(linter);
|
||||||
loadPluginJestRules(linter);
|
loadPluginJestRules(linter);
|
||||||
// TODO: more plugins
|
loadPluginReactRules(linter);
|
||||||
|
loadPluginReactHooksRules(linter);
|
||||||
|
loadPluginReactPerfRules(linter);
|
||||||
|
loadPluginNextRules(linter);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Generate entry and update status
|
// Generate entry and update status
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue