ilib-lint-react

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

An ilib-lint plugin for linting React files for internationalization (i18n) problems. Current stable version is 2.0.4, released as part of the ilib-mono monorepo. It provides parsers for JavaScript, JSX, TypeScript TSX, Flow, and properties files, along with rules like no-hard-coded-strings and no-nested-messages for react-intl. It is ESM-only, requires Node.js >=12, and is designed for integration with the ilib-lint framework. Key differentiators include deep i18n-aware linting for React apps, support for both JSX and TSX, and a plugin-based architecture.

error TypeError: ilib_lint_react__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function
cause Attempting to import the package as default export, but only named exports are provided.
fix
Use named imports: import { JSParser } from 'ilib-lint-react';
error Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/ilib-lint-react/index.js from not supported
cause Using require() to import an ESM-only module.
fix
Switch to import syntax or use dynamic import().
error Cannot find module 'ilib-lint-react/src/JSXParser'
cause Trying to deep-import a parser that is not exposed as a separate module.
fix
Import from the top-level package: import { JSXParser } from 'ilib-lint-react';
error Rule 'ban-formattedcompmessage' is not defined in ruleset 'react'
cause The rule name is misspelled or the rule is not loaded because of config issue.
fix
Ensure plugin is in 'plugins' list and ruleset 'react' is used. The rule name is 'ban-formattedcompmessage'.
breaking ESM-only: This package is ESM-only and cannot be imported with CommonJS require().
fix Use import syntax or dynamic import() in Node.js >=12.
deprecated FormattedCompMessage rule: The ban-formattedcompmessage rule is deprecated because the component is deprecated.
fix Update your code to avoid using FormattedCompMessage; the rule will flag it.
gotcha Parser selection: Use JSXParser for .js files if they contain JSX; JSParser will fail.
fix Set parser to 'jsx' in configuration for files that may contain JSX.
gotcha Node.js version requirement: Requires Node.js >=12 (ESM support); older versions not supported.
fix Upgrade Node.js to at least version 12.
breaking Plugin configuration: Must be specified in ilib-lint config under 'plugins' array.
fix Add "react" to the plugins list in your ilib-lint configuration.
npm install ilib-lint-react
yarn add ilib-lint-react
pnpm add ilib-lint-react

Configuration for ilib-lint to use the react plugin with parsers for JSX and JS files.

// ilib-lint.config.json
{
  "plugins": ["react"],
  "filetypes": {
    "jsx": {
      "parser": "jsx",
      "ruleset": ["react"]
    },
    "js": {
      "parser": "js",
      "ruleset": ["javascript"]
    }
  },
  "paths": {
    "src/**/*.jsx": "jsx",
    "src/**/*.js": "js"
  }
}

// Run lint:
// npx ilib-lint -c ilib-lint.config.json