ESLint Plugin String to Lingui
raw JSON → 0.25.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin (v0.25.0, actively maintained) that enforces proper usage of the Lingui internationalization library. It includes rules to detect untranslated strings, enforce `t` calls inside functions for dynamic language switching, prevent incorrect i18n macro usage, and validate message consistency against a reference JSON file. Key differentiators include support for JSX text, template literals, and customizable ignore patterns, making it suitable for large codebases migrating to Lingui v3+.
Common errors
error Configuration for rule "string-to-lingui/check-en-messages" is invalid: value.forEach is not a function ↓
cause The 'check-en-messages' rule expects an object, not an array.
fix
Replace the array with an object: ["warn", { "sourcePath": "..." }]
error Cannot read property 'some' of undefined ↓
cause The 'missing-lingui-transformation' rule is missing its options object when using sub-options like 'ignore'.
fix
Ensure the rule configuration includes an object: ["error", { "ignore": ["rgba"] }]
Warnings
gotcha The rule 'no-single-varibles-to-translate' has a typo in its name ('varibles' instead of 'variables'). This is intentional for backward compatibility, but may cause confusion. ↓
fix Use the exact rule name 'string-to-lingui/no-single-varibles-to-translate' in your configuration.
deprecated The rule 'i18n-number-call-in-function' is deprecated and likely replaced by 't-call-in-function' or a more general rule. ↓
fix Use 'string-to-lingui/t-call-in-function' instead.
gotcha The 'forbid-i18n-calls' rule may not cover all i18n methods (e.g., 'i18n.date'). Custom rules may be needed. ↓
fix Add additional rules for any i18n methods you want to forbid.
Install
npm install eslint-plugin-string-to-lingui yarn add eslint-plugin-string-to-lingui pnpm add eslint-plugin-string-to-lingui Imports
- plugin wrong
plugins: ['eslint-plugin-string-to-lingui']correctplugins: ['string-to-lingui']
Quickstart
// .eslintrc.json
{
"plugins": ["string-to-lingui"],
"rules": {
"string-to-lingui/missing-lingui-transformation": "error",
"string-to-lingui/t-call-in-function": "warn",
"string-to-lingui/macro-inside-t-and-i18": "error",
"string-to-lingui/t-should-be-before-macro": "warn",
"string-to-lingui/no-single-variables-to-translate": "warn",
"string-to-lingui/check-en-messages": ["warn", {
"sourcePath": "path/to/en/messages.json",
"similarityThreshold": 0.9,
"maxSuggestions": 3
}],
"string-to-lingui/text-restrictions": ["error", {
"rules": [{
"patterns": ["''", "’", "“"],
"message": "Use straight quotes and apostrophes."
}]
}],
"string-to-lingui/forbid-i18n-calls": ["error", {
"rules": [
{ "handlerName": "_", "message": "Use t`` from '@lingui/macro' instead" },
{ "handlerName": "number", "message": "Use formatCurrency or formatNumber instead" }
]
}]
}
}