eslint-plugin-t
This plugin contains lint rules related to internationalization, particularly for strings wrapped in t()
.
Installation
-
Add
eslint-plugin-t
to your devDependencies. -
Add
t
to theplugins
section of your ESLint configuration.
{
"plugins": ["t"]
}
- Enable the rule(s) that you want ESLint to enforce.
{
"rules": {
"t/string-literal": "warn"
}
}
Rules
There's currently just one lint rule in this package.
string-literal
This rule enforces that the first argument to t()
is a string literal. This is useful if you intend to statically extract language strings because static tooling can't evaluate expressions.
Example:
// Correct usage (no lint warning)
alert(t('Hello World!'));
// Incorrect usage (raises lint warning)
alert(t('Hello ' + Math.random().toString()));