Skip to content

Commit

Permalink
fix(no-unlocalized-strings): utilize ignoreFunction which is used as …
Browse files Browse the repository at this point in the history
…CallExpression (#21)
  • Loading branch information
radist2s authored Dec 8, 2023
1 parent 5078ea0 commit e84de6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/rules/no-unlocalized-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ const rule: RuleModule<string, Option[]> = {
return whitelists.some((item) => item.test(str))
}

function isValidFunctionCall({ callee }: TSESTree.CallExpression | TSESTree.NewExpression) {
function isValidFunctionCall({
callee,
}: TSESTree.CallExpression | TSESTree.NewExpression): boolean {
switch (callee.type) {
case TSESTree.AST_NODE_TYPES.MemberExpression: {
if (
Expand All @@ -116,6 +118,13 @@ const rule: RuleModule<string, Option[]> = {
}
return calleeWhitelists.simple.indexOf(callee.name) !== -1
}
case TSESTree.AST_NODE_TYPES.CallExpression: {
return (
(callee.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression ||
callee.callee.type === TSESTree.AST_NODE_TYPES.Identifier) &&
isValidFunctionCall(callee)
)
}
default:
return false
}
Expand Down
5 changes: 5 additions & 0 deletions tests/src/rules/no-unlocalized-strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ruleTester.run<string, Option[]>('no-unlocalized-strings', rule, {
{
code: 'i18n._(t`Hello ${nice}`)',
},
{ code: 't(i18n)({ message: `Hello ${name}` })' },
{
code: 'custom.wrapper()({message: "Hello!"})',
options: [{ ignoreFunction: ['custom.wrapper'] }],
},
{ code: 'name === `Hello brat` || name === `Nice have`' },
{ code: 'switch(a){ case `a`: break; default: break;}' },
{ code: 'a.indexOf(`ios`)' },
Expand Down

0 comments on commit e84de6e

Please sign in to comment.