Skip to content

Commit f768025

Browse files
committed
docs: add README with badges and rule documentation
1 parent ce491dc commit f768025

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# eslint-plugin-lingui-typescript
2+
3+
[![npm version](https://img.shields.io/npm/v/eslint-plugin-lingui-typescript.svg)](https://www.npmjs.com/package/eslint-plugin-lingui-typescript)
4+
[![CI](https://github.com/user/eslint-plugin-lingui-typescript/actions/workflows/ci.yml/badge.svg)](https://github.com/user/eslint-plugin-lingui-typescript/actions/workflows/ci.yml)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6+
7+
ESLint plugin for [Lingui](https://lingui.dev/) with TypeScript type-aware rules.
8+
9+
## Features
10+
11+
- 🔍 Detects incorrect usage of Lingui translation macros
12+
- 📝 Enforces simple, safe expressions inside translated messages
13+
- 🎯 Detects missing localization of user-visible text
14+
- 🧠 Respects TypeScript types to avoid false positives (e.g. string literal unions)
15+
16+
## Requirements
17+
18+
- Node.js ≥ 24
19+
- ESLint ≥ 9
20+
- TypeScript ≥ 5 (optional, for type-aware rules)
21+
22+
## Installation
23+
24+
```bash
25+
npm install --save-dev eslint-plugin-lingui-typescript
26+
```
27+
28+
## Usage
29+
30+
### ESLint Flat Config (eslint.config.ts)
31+
32+
```ts
33+
import linguiPlugin from "eslint-plugin-lingui-typescript"
34+
35+
export default [
36+
// Use recommended config
37+
linguiPlugin.configs["flat/recommended"],
38+
39+
// Or configure rules manually
40+
{
41+
plugins: {
42+
"lingui-ts": linguiPlugin
43+
},
44+
rules: {
45+
"lingui-ts/no-single-variable-message": "error"
46+
}
47+
}
48+
]
49+
```
50+
51+
## Rules
52+
53+
| Rule | Description | Recommended |
54+
|------|-------------|:-----------:|
55+
| [no-single-variable-message](docs/rules/no-single-variable-message.md) | Disallow messages that consist only of a single variable ||
56+
57+
### Planned Rules
58+
59+
- `no-complex-expressions-in-message` — Restrict complexity of expressions in messages
60+
- `no-nested-macros` — Disallow nesting Lingui macros
61+
- `no-single-tag-message` — Disallow messages with only a single markup tag
62+
- `valid-t-call-location` — Enforce valid locations for `t` macro calls
63+
- `no-unlocalized-strings` — Detect user-visible strings not wrapped in Lingui
64+
- `text-restrictions` — Enforce project-specific text restrictions
65+
- `consistent-plural-format` — Ensure consistent plural usage
66+
67+
## License
68+
69+
[MIT](LICENSE)
70+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# no-single-variable-message
2+
3+
Disallow Lingui messages that consist only of a single variable.
4+
5+
## Why?
6+
7+
Messages containing only a variable provide no context for translators and cannot be properly translated. The translator has no way of knowing what the variable represents or how to adapt the translation for different languages.
8+
9+
## Rule Details
10+
11+
This rule reports Lingui messages (`t` tagged templates and `<Trans>` components) that contain only a single variable with no surrounding text.
12+
13+
### ❌ Invalid
14+
15+
```tsx
16+
// Template literal with only a variable
17+
t`${status}`
18+
t`${user.name}`
19+
t` ${status} ` // whitespace doesn't count as text
20+
21+
// JSX with only a variable
22+
<Trans>{label}</Trans>
23+
<Trans>{user.name}</Trans>
24+
<Trans> {status} </Trans>
25+
```
26+
27+
### ✅ Valid
28+
29+
```tsx
30+
// Template literal with text
31+
t`Status: ${status}`
32+
t`Hello ${name}`
33+
t`${count} items`
34+
35+
// Multiple variables are fine (implies structure)
36+
t`${first} and ${second}`
37+
38+
// JSX with text
39+
<Trans>Hello {name}</Trans>
40+
<Trans>Status: {status}</Trans>
41+
<Trans>{count} items remaining</Trans>
42+
43+
// Plain text is fine
44+
t`Hello World`
45+
<Trans>Hello World</Trans>
46+
```
47+
48+
## Options
49+
50+
This rule has no options.
51+
52+
## When Not To Use It
53+
54+
If you have valid use cases for single-variable messages and handle the translation context elsewhere, you can disable this rule.
55+

0 commit comments

Comments
 (0)