Skip to content

Commit 1fba224

Browse files
committed
docs: document auto-ignore for styling props and numeric strings
1 parent ceae7a1 commit 1fba224

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ date.toLocaleDateString("de-DE", { weekday: "long" }) // Intl.DateTimeFormatOpt
2222
type Status = "idle" | "loading" | "error"
2323
const status: Status = "loading" // String literal union
2424

25+
// ✅ Automatically ignored - styling props and numeric strings
26+
<Box containerClassName="flex items-center" /> // *ClassName, *Class, *Color, etc.
27+
const price = "1,00€" // No letters = technical
28+
2529
// ❌ Reported - actual user-visible text
2630
const message = "Welcome to our app"
2731
<button>Save changes</button>
2832
```
2933

30-
**No configuration needed** for DOM APIs, Intl methods, or your own string literal union types. TypeScript already knows!
34+
**No configuration needed** for DOM APIs, Intl methods, string literal unions, styling props, or numeric strings. TypeScript + smart heuristics handle it!
3135

3236
### Smart Lingui Detection
3337

@@ -48,6 +52,8 @@ const label = t("save") // ❌ Not confused with Lingui
4852
- 📝 Enforces simple, safe expressions inside translated messages
4953
- 🎯 Detects missing localization of user-visible text
5054
- 🧠 Zero-config recognition of technical strings via TypeScript types
55+
- 🎨 Auto-ignores styling props (`*ClassName`, `*Color`, `*Style`, `*Icon`, `*Size`, `*Id`)
56+
- 🔢 Auto-ignores numeric/symbolic strings without letters (`"1,00€"`, `"12:30"`)
5157
- 🔒 Verifies Lingui macros actually come from `@lingui/*` packages (no false positives from similarly-named functions)
5258

5359
## Requirements
@@ -126,6 +132,8 @@ This plugin is a TypeScript-focused alternative to the official [eslint-plugin-l
126132
| **String literal unions** | Manual whitelist | ✅ Auto-detected |
127133
| **DOM API strings** | Manual whitelist | ✅ Auto-detected |
128134
| **Intl method arguments** | Manual whitelist | ✅ Auto-detected |
135+
| **Styling props** (`*ClassName`, etc.) | Manual whitelist | ✅ Auto-detected |
136+
| **Numeric strings** (`"1,00€"`) | Manual whitelist | ✅ Auto-detected |
129137
| **Lingui macro verification** | Name-based only | ✅ Verifies package origin |
130138
| **ESLint version** | 8.x | 9.x (flat config) |
131139
| **Config format** | Legacy `.eslintrc` | Flat config only |

docs/rules/no-unlocalized-strings.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ Default:
153153

154154
**Note**: Properties like `type`, `role`, `href`, `id` are NOT in the default list because TypeScript automatically detects them as technical when they have string literal union types.
155155

156+
#### Auto-Detected Styling Properties
157+
158+
In addition to the explicit list, the rule automatically ignores camelCase properties ending with common styling suffixes:
159+
160+
| Suffix | Examples |
161+
|--------|----------|
162+
| `ClassName` | `containerClassName`, `wrapperClassName` |
163+
| `Class` | `buttonClass`, `inputClass` |
164+
| `Color` | `backgroundColor`, `borderColor` |
165+
| `Style` | `containerStyle`, `buttonStyle` |
166+
| `Icon` | `leftIcon`, `statusIcon` |
167+
| `Size` | `fontSize`, `iconSize` |
168+
| `Id` | `containerId`, `elementId` |
169+
170+
```tsx
171+
// All automatically ignored - no configuration needed
172+
<Button containerClassName="flex items-center" />
173+
<Input wrapperClassName="mt-4" />
174+
<Box backgroundColor="#ff0000" />
175+
<Avatar iconSize="24" />
176+
```
177+
178+
This covers common patterns in component libraries like Chakra UI, Material UI, and custom component props.
179+
156180
### `ignoreNames`
157181

158182
Array of variable names to ignore.
@@ -193,6 +217,24 @@ The rule uses heuristics to determine if a string looks like UI text:
193217
- Identifiers without spaces (`myFunction`, `my-css-class`)
194218
- CSS selectors (`:hover`, `.class`, `#id`)
195219
- SVG path data (`M10 10`, `L20 30`)
220+
- Strings without any letters — numeric/symbolic only
221+
222+
### Numeric and Symbolic Strings
223+
224+
Strings containing only numbers, punctuation, and symbols are automatically ignored:
225+
226+
```tsx
227+
// All automatically ignored - no letters means no UI text
228+
const price = "1,00€"
229+
const amount = "$99.99"
230+
const time = "12:30"
231+
const date = "2024-01-15"
232+
const percentage = "100%"
233+
const list = "1,00 2,00 3,00"
234+
const arrows = "→ ← ↑ ↓"
235+
```
236+
237+
This uses Unicode letter detection (`\p{L}`), so accented characters like `ä`, `ö`, `ü`, `é` are correctly recognized as letters.
196238

197239
## When Not To Use It
198240

0 commit comments

Comments
 (0)