Skip to content

Commit d75cf3b

Browse files
committed
refactor: rename rules to match eslint-plugin-lingui
Align rule names with the original plugin for easier migration: - valid-t-call-location → t-call-in-function - no-single-variable-message → no-single-variables-to-translate - no-complex-expressions-in-message → no-expression-in-message - no-single-tag-message → no-single-tag-to-translate
1 parent 573e3ae commit d75cf3b

14 files changed

+45
-43
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Or configure rules manually:
8282
},
8383
rules: {
8484
"lingui-ts/no-unlocalized-strings": "error",
85-
"lingui-ts/no-single-variable-message": "error"
85+
"lingui-ts/no-single-variables-to-translate": "error"
8686
}
8787
}
8888
```
@@ -92,17 +92,17 @@ Or configure rules manually:
9292
| Rule | Description | Recommended |
9393
|------|-------------|:-----------:|
9494
| [no-unlocalized-strings](docs/rules/no-unlocalized-strings.md) | Detects user-visible strings not wrapped in Lingui macros. Uses TypeScript types to automatically ignore technical strings like string literal unions, DOM APIs, and Intl methods. ||
95-
| [no-single-variable-message](docs/rules/no-single-variable-message.md) | Disallows messages that consist only of variables without surrounding text. Such messages provide no context for translators. ||
96-
| [no-single-tag-message](docs/rules/no-single-tag-message.md) | Disallows `<Trans>` components that contain only a single JSX element without text. The wrapped element should have surrounding text for context. ||
95+
| [no-single-variables-to-translate](docs/rules/no-single-variables-to-translate.md) | Disallows messages that consist only of variables without surrounding text. Such messages provide no context for translators. ||
96+
| [no-single-tag-to-translate](docs/rules/no-single-tag-to-translate.md) | Disallows `<Trans>` components that contain only a single JSX element without text. The wrapped element should have surrounding text for context. ||
9797
| [no-nested-macros](docs/rules/no-nested-macros.md) | Prevents nesting Lingui macros inside each other (e.g., `t` inside `<Trans>`). Nested macros create invalid message catalogs and confuse translators. ||
98-
| [no-complex-expressions-in-message](docs/rules/no-complex-expressions-in-message.md) | Restricts embedded expressions to simple identifiers only. Complex expressions like `${user.name}` or `${formatPrice(x)}` must be extracted to named variables first. ||
99-
| [valid-t-call-location](docs/rules/valid-t-call-location.md) | Ensures `t` macro calls are inside functions or class properties, not at module scope. Module-level calls execute before i18n is initialized and won't update on locale change. ||
98+
| [no-expression-in-message](docs/rules/no-expression-in-message.md) | Restricts embedded expressions to simple identifiers only. Complex expressions like `${user.name}` or `${formatPrice(x)}` must be extracted to named variables first. ||
99+
| [t-call-in-function](docs/rules/t-call-in-function.md) | Ensures `t` macro calls are inside functions or class properties, not at module scope. Module-level calls execute before i18n is initialized and won't update on locale change. ||
100100
| [consistent-plural-format](docs/rules/consistent-plural-format.md) | Enforces consistent plural value format — either `#` hash syntax or `${var}` template literals throughout the codebase. ||
101101
| [text-restrictions](docs/rules/text-restrictions.md) | Enforces project-specific text restrictions with custom patterns and messages. Requires configuration. ||
102102

103103
## Migrating from eslint-plugin-lingui
104104

105-
This plugin is a TypeScript-focused alternative to the official [eslint-plugin-lingui](https://github.com/lingui/eslint-plugin-lingui). Here are the key differences:
105+
This plugin is a TypeScript-focused alternative to the official [eslint-plugin-lingui](https://github.com/lingui/eslint-plugin-lingui). Rule names are compatible where possible, making migration straightforward.
106106

107107
### Key Differences
108108

@@ -128,10 +128,10 @@ This plugin is a TypeScript-focused alternative to the official [eslint-plugin-l
128128
| eslint-plugin-lingui | eslint-plugin-lingui-typescript |
129129
|---------------------|--------------------------------|
130130
| `lingui/no-unlocalized-strings` | `lingui-ts/no-unlocalized-strings` |
131-
| `lingui/t-call-in-function` | `lingui-ts/valid-t-call-location` |
132-
| `lingui/no-single-variables-to-translate` | `lingui-ts/no-single-variable-message` |
133-
| `lingui/no-expression-in-message` | `lingui-ts/no-complex-expressions-in-message` |
134-
| `lingui/no-single-tag-to-translate` | `lingui-ts/no-single-tag-message` |
131+
| `lingui/t-call-in-function` | `lingui-ts/t-call-in-function` |
132+
| `lingui/no-single-variables-to-translate` | `lingui-ts/no-single-variables-to-translate` |
133+
| `lingui/no-expression-in-message` | `lingui-ts/no-expression-in-message` |
134+
| `lingui/no-single-tag-to-translate` | `lingui-ts/no-single-tag-to-translate` |
135135
| `lingui/text-restrictions` | `lingui-ts/text-restrictions` |
136136
|| `lingui-ts/no-nested-macros` (new) |
137137
|| `lingui-ts/consistent-plural-format` (new) |
@@ -159,7 +159,9 @@ This plugin is a TypeScript-focused alternative to the official [eslint-plugin-l
159159
]
160160
```
161161

162-
4. Review your ignore lists — many entries may no longer be needed thanks to type-aware detection.
162+
4. Update rule names in your config (change prefix from `lingui/` to `lingui-ts/`).
163+
164+
5. Review your ignore lists — many entries may no longer be needed thanks to type-aware detection.
163165

164166
## Related Projects
165167

docs/rules/no-complex-expressions-in-message.md renamed to docs/rules/no-expression-in-message.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# no-complex-expressions-in-message
1+
# no-expression-in-message
22

33
Disallow complex expressions in Lingui messages — only simple identifiers are allowed.
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# no-single-tag-message
1+
# no-single-tag-to-translate
22

33
Disallow Lingui messages that consist only of a single JSX element without surrounding text.
44

docs/rules/no-single-variable-message.md renamed to docs/rules/no-single-variables-to-translate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# no-single-variable-message
1+
# no-single-variables-to-translate
22

33
Disallow Lingui messages that consist only of a single variable.
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# valid-t-call-location
1+
# t-call-in-function
22

33
Enforce that `t` macro calls are inside functions, not at module top-level.
44

src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import { consistentPluralFormat } from "./rules/consistent-plural-format.js"
8-
import { noComplexExpressionsInMessage } from "./rules/no-complex-expressions-in-message.js"
8+
import { noExpressionInMessage } from "./rules/no-expression-in-message.js"
99
import { noNestedMacros } from "./rules/no-nested-macros.js"
10-
import { noSingleTagMessage } from "./rules/no-single-tag-message.js"
11-
import { noSingleVariableMessage } from "./rules/no-single-variable-message.js"
10+
import { noSingleTagToTranslate } from "./rules/no-single-tag-to-translate.js"
11+
import { noSingleVariablesToTranslate } from "./rules/no-single-variables-to-translate.js"
1212
import { noUnlocalizedStrings } from "./rules/no-unlocalized-strings.js"
1313
import { textRestrictions } from "./rules/text-restrictions.js"
14-
import { validTCallLocation } from "./rules/valid-t-call-location.js"
14+
import { tCallInFunction } from "./rules/t-call-in-function.js"
1515

1616
const plugin = {
1717
meta: {
@@ -20,13 +20,13 @@ const plugin = {
2020
},
2121
rules: {
2222
"consistent-plural-format": consistentPluralFormat,
23-
"no-complex-expressions-in-message": noComplexExpressionsInMessage,
23+
"no-expression-in-message": noExpressionInMessage,
2424
"no-nested-macros": noNestedMacros,
25-
"no-single-tag-message": noSingleTagMessage,
26-
"no-single-variable-message": noSingleVariableMessage,
25+
"no-single-tag-to-translate": noSingleTagToTranslate,
26+
"no-single-variables-to-translate": noSingleVariablesToTranslate,
2727
"no-unlocalized-strings": noUnlocalizedStrings,
2828
"text-restrictions": textRestrictions,
29-
"valid-t-call-location": validTCallLocation
29+
"t-call-in-function": tCallInFunction
3030
},
3131
configs: {} as Record<string, unknown>
3232
}
@@ -39,12 +39,12 @@ plugin.configs = {
3939
},
4040
rules: {
4141
"lingui-ts/consistent-plural-format": "error",
42-
"lingui-ts/no-complex-expressions-in-message": "error",
42+
"lingui-ts/no-expression-in-message": "error",
4343
"lingui-ts/no-nested-macros": "error",
44-
"lingui-ts/no-single-tag-message": "error",
45-
"lingui-ts/no-single-variable-message": "error",
44+
"lingui-ts/no-single-tag-to-translate": "error",
45+
"lingui-ts/no-single-variables-to-translate": "error",
4646
"lingui-ts/no-unlocalized-strings": "error",
47-
"lingui-ts/valid-t-call-location": "error"
47+
"lingui-ts/t-call-in-function": "error"
4848
// text-restrictions not in recommended (requires configuration)
4949
}
5050
}

src/rules/no-complex-expressions-in-message.test.ts renamed to src/rules/no-expression-in-message.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RuleTester } from "@typescript-eslint/rule-tester"
22
import { afterAll, describe, it } from "vitest"
33

4-
import { noComplexExpressionsInMessage } from "./no-complex-expressions-in-message.js"
4+
import { noExpressionInMessage } from "./no-expression-in-message.js"
55

66
RuleTester.afterAll = afterAll
77
RuleTester.describe = describe
@@ -19,7 +19,7 @@ const ruleTester = new RuleTester({
1919
}
2020
})
2121

22-
ruleTester.run("no-complex-expressions-in-message", noComplexExpressionsInMessage, {
22+
ruleTester.run("no-expression-in-message", noExpressionInMessage, {
2323
valid: [
2424
// ==================== Simple Identifiers ====================
2525
// The ONLY thing allowed in Lingui messages

src/rules/no-complex-expressions-in-message.ts renamed to src/rules/no-expression-in-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ function isWhitespaceExpression(expr: TSESTree.Expression): boolean {
7171
// Rule Definition
7272
// ============================================================================
7373

74-
export const noComplexExpressionsInMessage = createRule<[], MessageId>({
75-
name: "no-complex-expressions-in-message",
74+
export const noExpressionInMessage = createRule<[], MessageId>({
75+
name: "no-expression-in-message",
7676
meta: {
7777
type: "problem",
7878
docs: {

src/rules/no-single-tag-message.test.ts renamed to src/rules/no-single-tag-to-translate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RuleTester } from "@typescript-eslint/rule-tester"
22
import { afterAll, describe, it } from "vitest"
33

4-
import { noSingleTagMessage } from "./no-single-tag-message.js"
4+
import { noSingleTagToTranslate } from "./no-single-tag-to-translate.js"
55

66
RuleTester.afterAll = afterAll
77
RuleTester.describe = describe
@@ -19,7 +19,7 @@ const ruleTester = new RuleTester({
1919
}
2020
})
2121

22-
ruleTester.run("no-single-tag-message", noSingleTagMessage, {
22+
ruleTester.run("no-single-tag-to-translate", noSingleTagToTranslate, {
2323
valid: [
2424
// Text before element
2525
"<Trans>Read <a href='/terms'>terms</a></Trans>",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function isSingleTagJSX(children: TSESTree.JSXChild[]): boolean {
2323
return onlyChild?.type === AST_NODE_TYPES.JSXElement || onlyChild?.type === AST_NODE_TYPES.JSXFragment
2424
}
2525

26-
export const noSingleTagMessage = createRule<[], MessageId>({
27-
name: "no-single-tag-message",
26+
export const noSingleTagToTranslate = createRule<[], MessageId>({
27+
name: "no-single-tag-to-translate",
2828
meta: {
2929
type: "problem",
3030
docs: {

0 commit comments

Comments
 (0)