From 7a8d0628580ca6a5f14858b3956f9a483671919d Mon Sep 17 00:00:00 2001 From: Tilman Stehr Date: Fri, 11 Oct 2024 14:08:39 +0200 Subject: [PATCH] feat: allow calls to plural function in no-expression-in-message (#48) --- src/rules/no-expression-in-message.ts | 9 +++++++-- tests/src/rules/no-expression-in-message.test.ts | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rules/no-expression-in-message.ts b/src/rules/no-expression-in-message.ts index 6a7ad57..9d2e9e0 100644 --- a/src/rules/no-expression-in-message.ts +++ b/src/rules/no-expression-in-message.ts @@ -29,8 +29,13 @@ export const rule = createRule({ return { 'TemplateLiteral:exit'(node: TSESTree.TemplateLiteral) { const noneIdentifierExpressions = node.expressions - ? node.expressions.filter((expression: { type: string }) => { - return expression.type !== TSESTree.AST_NODE_TYPES.Identifier + ? node.expressions.filter((expression) => { + const isIdentifier = expression.type === TSESTree.AST_NODE_TYPES.Identifier + const isCallToPluralFunction = + expression.type === TSESTree.AST_NODE_TYPES.CallExpression && + expression.callee.type === TSESTree.AST_NODE_TYPES.Identifier && + expression.callee.name === 'plural' + return !isIdentifier && !isCallToPluralFunction }) : [] diff --git a/tests/src/rules/no-expression-in-message.test.ts b/tests/src/rules/no-expression-in-message.test.ts index 849b7f4..447fec9 100644 --- a/tests/src/rules/no-expression-in-message.test.ts +++ b/tests/src/rules/no-expression-in-message.test.ts @@ -28,6 +28,9 @@ ruleTester.run(name, rule, { { code: 't`Hello ${hello}`', }, + { + code: 't`Hello ${plural()}`', + }, ], invalid: [ {