Skip to content

Commit 1426d35

Browse files
committed
fix(no-unlocalized-strings): recognize t() function call syntax
The t macro can be used both as tagged template (t`Hello`) and as a function call with object syntax (t({ message, context })). Only the tagged template was recognized, causing false positives for the object syntax used to provide translator context.
1 parent e6d0edb commit 1426d35

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/rules/no-unlocalized-strings.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ ruleTester.run("no-unlocalized-strings", noUnlocalizedStrings, {
4141
{ code: '<Select value={gender} male="He" female="She" other="They" />', filename: "test.tsx" },
4242
{ code: '<SelectOrdinal value={pos} one="#st" two="#nd" few="#rd" other="#th" />', filename: "test.tsx" },
4343

44+
// Inside t() function call with object syntax (not just tagged template)
45+
{ code: 't({ message: "Hello World" })', filename: "test.tsx" },
46+
{ code: 't({ message: "e.g., Philippe L.", context: "placeholder for full name field" })', filename: "test.tsx" },
47+
{ code: 't({ id: "msg.hello", comment: "Greetings at homepage", message: "Hello World" })', filename: "test.tsx" },
48+
4449
// Inside msg/defineMessage
4550
{ code: 'msg({ message: "Hello World" })', filename: "test.tsx" },
4651
{ code: 'defineMessage({ message: "Save changes" })', filename: "test.tsx" },

src/rules/no-unlocalized-strings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ const LINGUI_TAGGED_TEMPLATES = new Set(["t"])
6464
/** JSX components from Lingui that handle localization */
6565
const LINGUI_JSX_COMPONENTS = new Set(["Trans", "Plural", "Select", "SelectOrdinal"])
6666

67-
/** Function-style macros from Lingui */
68-
const LINGUI_FUNCTION_MACROS = new Set(["msg", "defineMessage", "plural", "select", "selectOrdinal"])
67+
/** Function-style macros from Lingui (t can be both tagged template and function call) */
68+
const LINGUI_FUNCTION_MACROS = new Set(["t", "msg", "defineMessage", "plural", "select", "selectOrdinal"])
6969

7070
/**
7171
* Checks if a symbol originates from a Lingui package using TypeScript's type system.

0 commit comments

Comments
 (0)