eslint-plugin-t

raw JSON →
1.7.1 verified Fri May 01 auth: no javascript

An ESLint plugin providing lint rules for internationalization, especially for strings wrapped in `t()` calls. The current stable version is 1.7.1. It helps enforce consistent use of translation function `t()` and can detect missing translations or incorrect usage. Compared to other i18n lint plugins, it focuses specifically on the `t()` pattern used in many JavaScript projects. Release cadence is irregular as it's a smaller community project.

error Error: Failed to load plugin 't': Cannot find module 'eslint-plugin-t'
cause Missing dependency or not installed as a dev dependency
fix
Run npm install --save-dev eslint-plugin-t
error ESLint: Rule 't/no-literal-string' is not defined
cause Plugin not added to plugins array in ESLint config
fix
Add 't' to the plugins array in your ESLint config
error TypeError: Cannot read properties of undefined (reading 't-no-literal-string')
cause Incorrect import or destructuring of rules from plugin
fix
Access rules via imported plugin object: plugin.rules['t-no-literal-string']
breaking Version 1.0.0 changed default export from object with rules to a plugin object requiring different import
fix Update import to use 'eslint-plugin-t' and configure rules under plugins and rules
deprecated Rule 't/no-literal-string' was deprecated in v1.5.0 in favor of 't/valid-t-usage'
fix Replace 't/no-literal-string' with 't/valid-t-usage'
gotcha If using TypeScript, the plugin may not recognize t() calls without type information; need to define t() signature in global types
fix Add declare function t(key: string): string; in your project's types
breaking Version 1.7.0 changed rule configs to use severity strings 'error'/'warn' instead of numbers 2/1
fix Update rule configs to use 'error' or 'warn' strings
npm install eslint-plugin-t
yarn add eslint-plugin-t
pnpm add eslint-plugin-t

Shows basic setup of eslint-plugin-t with two rules and demonstrates linting behavior on t() usage.

// .eslintrc.js
module.exports = {
  plugins: ['t'],
  rules: {
    't/no-literal-string': 'error',
    't/no-unused-t': 'warn',
  },
};

// Source code with t()
const msg = t('Hello World'); // allowed
const bad = 'Hello World';    // error with no-literal-string