Skip to content

Commit

Permalink
feat: allow calls to plural function in no-expression-in-message (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
tstehr authored Oct 11, 2024
1 parent f99a709 commit 7a8d062
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/rules/no-expression-in-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
: []

Expand Down
3 changes: 3 additions & 0 deletions tests/src/rules/no-expression-in-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ruleTester.run(name, rule, {
{
code: 't`Hello ${hello}`',
},
{
code: 't`Hello ${plural()}`',
},
],
invalid: [
{
Expand Down

0 comments on commit 7a8d062

Please sign in to comment.