Skip to content

Commit

Permalink
feat(docs): add tracking for plugins "promise" and "vitest" (#4668)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix authored Aug 5, 2024
1 parent 5327acd commit 5c62f17
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tasks/lint_rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"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-unicorn": "latest",
"eslint-plugin-vitest": "latest"
}
}
43 changes: 43 additions & 0 deletions tasks/lint_rules/src/eslint-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ 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");

/** @param {import("eslint").Linter} linter */
const loadPluginTypeScriptRules = (linter) => {
Expand Down Expand Up @@ -217,6 +227,35 @@ const loadPluginNextRules = (linter) => {
}
};

/** @param {import("eslint").Linter} linter */
const loadPluginPromiseRules = (linter) => {
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 =
pluginPromiseRecommendedRules.has(prefixedName);

linter.defineRule(prefixedName, rule);
}
}

/** @param {import("eslint").Linter} linter */
const loadPluginVitestRules = (linter) => {
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 = pluginVitestRecommendedRules.has(prefixedName);

linter.defineRule(prefixedName, rule);
}
}

/**
* @typedef {{
* npm: string[];
Expand All @@ -242,6 +281,8 @@ 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: 4655 }],
["vitest", { npm: ["eslint-plugin-vitest"], issueNo: 4656 }],
]);

// All rules(including deprecated, recommended) are loaded initially.
Expand All @@ -262,4 +303,6 @@ exports.loadTargetPluginRules = (linter) => {
loadPluginReactRules(linter);
loadPluginReactPerfRules(linter);
loadPluginNextRules(linter);
loadPluginPromiseRules(linter);
loadPluginVitestRules(linter);
};

0 comments on commit 5c62f17

Please sign in to comment.