/
githubmirror
/
eslint-plugin
Обзор
Документация
Войти
/
githubmirror
/
eslint-plugin
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/rules/commands/noCommandInCommandName.ts
49 строк
2 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 { docsUrl, ruleCreator } from "../../ruleCreator.js"; export default ruleCreator({ meta: { type: "suggestion" as const, docs: { description: "Disallow using the word 'command' in a command name.", url: docsUrl("no-command-in-command-name", "commands"), }, messages: { commandInName: "Adding `command` to the command name is not necessary.", }, schema: [], }, defaultOptions: [], create(context) { 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 ( 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("command") ) { context.report({ node: property, messageId: "commandInName", }); } } }, }; }, });