/
githubmirror
/
eslint-plugin
Обзор
Документация
Войти
/
githubmirror
/
eslint-plugin
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/rules/commands/noPluginNameInCommandName.ts
68 строк
3 KB
saberzero1
refactor: replace all hardcoded URLs with docsUrl()
10 июн 2026, 16:14
10 июн 2026, 16:14
396eae1
Код
Авторство
О чём код?
import { TSESTree } from "@typescript-eslint/utils"; import { getManifest } from "../../manifest.js"; import { docsUrl, ruleCreator } from "../../ruleCreator.js"; type Options = [{ pluginName?: string }?]; export default ruleCreator<Options, "pluginName">({ meta: { type: "suggestion" as const, docs: { description: "Disallow including the plugin name in a command name.", url: docsUrl("no-plugin-name-in-command-name", "commands"), }, messages: { pluginName: "The command name should not include the plugin name, the plugin name is already shown next to the command name in the UI.", }, schema: [ { type: "object", properties: { pluginName: { type: "string", description: "The plugin name to check against. Defaults to manifest.json name.", }, }, additionalProperties: false, }, ], }, defaultOptions: [{}], create(context) { const options = context.options[0] || {}; const pluginName = options.pluginName ?? getManifest()?.name; return { CallExpression(node: TSESTree.CallExpression) { if ( node.callee.type !== TSESTree.AST_NODE_TYPES.MemberExpression || node.callee.property.type !== TSESTree.AST_NODE_TYPES.Identifier || node.callee.property.name !== "addCommand" || node.arguments[0]?.type !== TSESTree.AST_NODE_TYPES.ObjectExpression ) { return; } const commandObject = node.arguments[0]; for (const property of commandObject.properties) { if ( typeof pluginName === "string" && property.type === TSESTree.AST_NODE_TYPES.Property && property.key.type === TSESTree.AST_NODE_TYPES.Identifier && property.key.name === "name" && property.value.type === TSESTree.AST_NODE_TYPES.Literal && typeof property.value.value === "string" && property.value.value .toLowerCase() .includes(pluginName.toLowerCase()) ) { context.report({ node: property, messageId: "pluginName", }); } } }, }; }, });