Skip to content

Commit

Permalink
feat: extend function call support for no-expression-in-message to se…
Browse files Browse the repository at this point in the history
…lect and selectOrdinal
  • Loading branch information
tstehr committed Oct 11, 2024
1 parent 7a8d062 commit 7dbbdc4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rules/no-expression-in-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ export const rule = createRule({
defaultOptions: [],

create: function (context) {
const linguiMacroFunctionNames = ['plural', 'select', 'selectOrdinal']

return {
'TemplateLiteral:exit'(node: TSESTree.TemplateLiteral) {
const noneIdentifierExpressions = node.expressions
? node.expressions.filter((expression) => {
const isIdentifier = expression.type === TSESTree.AST_NODE_TYPES.Identifier
const isCallToPluralFunction =
const isCallToLinguiMacro =
expression.type === TSESTree.AST_NODE_TYPES.CallExpression &&
expression.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
expression.callee.name === 'plural'
return !isIdentifier && !isCallToPluralFunction
linguiMacroFunctionNames.includes(expression.callee.name)
return !isIdentifier && !isCallToLinguiMacro
})
: []

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

0 comments on commit 7dbbdc4

Please sign in to comment.