diff --git a/src/rules/t-call-in-function.ts b/src/rules/t-call-in-function.ts index 4f0bdc0..85bd065 100644 --- a/src/rules/t-call-in-function.ts +++ b/src/rules/t-call-in-function.ts @@ -13,7 +13,7 @@ const rule: RuleModule = { recommended: 'error' as RuleRecommendation, }, messages: { - default: 't`` call should be inside function', + default: 't`` and t() call should be inside function', }, schema: [ { @@ -56,7 +56,19 @@ const rule: RuleModule = { ['ClassDeclaration TaggedTemplateExpression'](node: TSESTree.TaggedTemplateExpression) { handler(node) }, - + ['CallExpression:exit'](node: TSESTree.CallExpression) { + const scope = context.getScope() + if ( + scope.type === 'module' && + node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && + node.callee.name === 't' + ) { + context.report({ + node, + messageId: 'default', + }) + } + }, ['TaggedTemplateExpression:exit'](node: TSESTree.TaggedTemplateExpression) { if (visited.has(node)) return if (!isTTaggedTemplateExpression(node)) { diff --git a/tests/src/rules/t-call-in-function.test.ts b/tests/src/rules/t-call-in-function.test.ts index 954289d..9879f36 100644 --- a/tests/src/rules/t-call-in-function.test.ts +++ b/tests/src/rules/t-call-in-function.test.ts @@ -34,7 +34,14 @@ ruleTester.run('t-call-in-function', rule, { padding: ${tokens.spacing20};\ `', }, + { + code: 'const a = () => {t("Hello")}', + }, ], - invalid: [{ code: 't`Hello`', errors }], + invalid: [ + { code: 't`Hello`', errors }, + { code: 't("Hello")', errors }, + { code: 'const hello = [t({id:"hello", message:"hello"})]', errors }, + ], })