eslint-plugin-formatjs

raw JSON →
6.4.6 verified Sat Apr 25 auth: no javascript

ESLint plugin for FormatJS that enforces best practices for internationalized messages. Current stable version is 6.4.6, with regular releases tied to the FormatJS monorepo. It provides rules for validating ICU message syntax, enforcing message extraction patterns, preventing missing descriptions, and ensuring consistent translation keys. Differentiates from generic i18n ESLint plugins by deep integration with intl-messageformat and react-intl, supporting both flat and nested message structures, and offering auto-fix for many rules. Requires ESLint 9 or 10.

error Error: Failed to load plugin 'formatjs': Cannot find module 'eslint-plugin-formatjs'
cause Plugin not installed or ESLint cannot resolve it.
fix
npm install eslint-plugin-formatjs --save-dev
error TypeError: (0 , _eslintPluginFormatjs.default) is not a function
cause Using require() on an ESM-only module.
fix
Change to import statement: import eslintPluginFormatjs from 'eslint-plugin-formatjs'
error ESLint couldn't determine the plugin 'formatjs' uniquely. This may be caused by a plugin conflict.
cause Multiple versions of the plugin installed or name collision.
fix
Check node_modules for duplicate installations and deduplicate with npm dedupe.
error Parsing error: The keyword 'import' is reserved
cause ESLint parser does not support ES modules; need to configure parserOptions.
fix
Set parserOptions: { sourceType: 'module' } in ESLint config.
breaking Version 6 dropped support for ESLint 8; requires ESLint 9 or 10.
fix Upgrade ESLint to 9.x or 10.x, or use eslint-plugin-formatjs@5.x.
gotcha The plugin is ESM-only since v6; using require() will throw an error.
fix Use import syntax or dynamic import() in CommonJS projects.
deprecated The 'flat' config is now the default; the old .eslintrc format is deprecated for this plugin.
fix Migrate to ESLint flat config using configs['flat'].
gotcha Some rules require @formatjs/ts-transformer to be installed when using TypeScript.
fix Install @formatjs/ts-transformer as a dev dependency for TypeScript projects.
gotcha The rule 'formatjs/no-literal-string-in-jsx' only works with react-intl; requires babel-plugin-formatjs or equivalent.
fix Ensure your build pipeline includes babel-plugin-formatjs or @formatjs/unplugin.
npm install eslint-plugin-formatjs
yarn add eslint-plugin-formatjs
pnpm add eslint-plugin-formatjs

ESLint flat config setup with two FormatJS rules enabled.

import eslintPluginFormatjs from 'eslint-plugin-formatjs';
export default [
  {
    plugins: {
      formatjs: eslintPluginFormatjs
    },
    rules: {
      'formatjs/enforce-description': 'error',
      'formatjs/no-literal-string-in-jsx': 'warn'
    }
  }
];