@calm/eslint-plugin-react-intl

中文文档
1.4.1发布于 2020/02/28MITCommonJS近 30 天下载 13万

Linter for React-Intl integration

此软件包已被标记为弃用

This package is no longer actively maintained by Calm. It remains available for compatibility with existing consumers, but new projects should avoid depending on it.

原始使用文档
文档目录4 节
  1. Use Cases
  2. Installation
  3. Usage
  4. Supported Rules

@calm/eslint-plugin-react-intl

This is a plugin to ensure that Intl translations are being made correctly with react-intl. Since they should be stored in an object for translation, this disables plain text between html tags.

The plugin is actively supported by the Calm engineering team, and contributions/concerns are welcome at https://github.com/calm/eslint-plugin-react-intl.

There are three options to enable, and we recommend enabling all of them to ensure proper translations in all languages.

The { noTrailingWhitespace: true } option is set by default and is not necessary to declare in the rules section. This is recommended as some languages don't have spaces between words. Additionally, the option ignoreLinks is set to true by default. Depending on your use case, you may want to disable this.

Use Cases

Formatted Message validation

  • Checks to make sure plain text doesn't exist within html tags (should be translated)
  • <a> tags by default are not checked (this can be disabled)
  • Numbers are ignored (they're the same in every language)
  • Trailing whitespace is not allowed (this can be disabled)
  • Non-alphanumeric values are ignored (such as -)
  • Can enable enforcing label, aria-label attributes being translated (<track label="subtitles" />)
  • Can enable enforcing alt attributes being translated (<img alt="description" />)
  • Can enable enforcing inputProps being translated (<Checkbox value="checkedA" inputProps={{ 'aria-label': 'Checkbox A' }} />)

Missing Values validation

  • In defaultMessage attributes within components, {variable} declarations must be declared in the values attribute
  • It will look over anything before a comma, allowing for FormatJS plurals
    • Ex. defaultMessage="{number} {number, plural, one {Day} other {Days}}" will resolve 1 variable as number

Missing Attribute validation

  • components must have both defaultMessage and id attributes set
    • Calm chooses to always require these, but you can optionally disable defaultMessage with option requireDefaultMessage : false
  • defaultMessage and id attributes cannot be empty
  • Spread operator by default is not allowed
    • Spread operator can't be evaluated by eslint's AST, so translations can't be guaranteed
  • requireDescription can optionally be set to require that all translations contain the description attribute
  • Use the formatDefineMessages: true option in order to also check the defineMessages declaration from react-intl
    • BE CAREFUL - This assumes that defineMessages will always mean the react-intl method, so do not declare other defineMessages functions unless they maintain the same formatting as react-intl
  • Optional requireIdAsString: false will allow for variables in the id field
    • BE CAREFUL - variables in id fields can result in duplicate strings being translated, as well as the possibility of a changed variable leading to an id without a translation associated with it

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install @calm/eslint-plugin-react-intl:

$ npm install @calm/eslint-plugin-react-intl --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install @calm/eslint-plugin-react-intl globally.

Usage

Add @calm/react-intl to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "@calm/react-intl"
    ]
}

Then configure the rules you want to use under the rules section. It's recommended that you explicitly set each option.
The rules (with their default settings) are listed below.

{
    "rules": {
        "@calm/react-intl/missing-formatted-message": [2,
          {
            "noTrailingWhitespace": true,
            "ignoreLinks": true,
            "enforceLabels": false,
            "enforceImageAlts": false,
            "enforceInputProps": false
          }
        ],
        "@calm/react-intl/missing-attribute": [2,
            {
                "noTrailingWhitespace": true,
                "noSpreadOperator": true,
                "requireDescription": false,
                "formatDefineMessages": false,
                "requireIdAsString": true,
                "requireDefaultMessage": true,
            }
        ],
        "@calm/react-intl/missing-values": 2
    }
}

Supported Rules

  • missing-formatted-message
  • missing-attribute
  • missing-values

版本与发布记录

@calm/eslint-plugin-react-intl 共发布 10 个版本,首次发布于 2019/04/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.1latest2020/02/286 年前
1.4.02019/12/126 年前
1.3.62019/06/147 年前
1.3.52019/05/227 年前
1.3.42019/05/227 年前
1.3.32019/05/227 年前

关于 @calm/eslint-plugin-react-intl 的常见问题

@calm/eslint-plugin-react-intl 是什么?

Linter for React-Intl integration注意:该包已被作者标记为弃用——This package is no longer actively maintained by Calm. It remains available for compatibility with existing consumers, but new projects should avoid depending on it.

如何安装 @calm/eslint-plugin-react-intl?

在项目目录运行 npm install @calm/eslint-plugin-react-intl,或使用 pnpm add / yarn add / bun add。

@calm/eslint-plugin-react-intl 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/calm__eslint-plugin-react-intl 是否存在。

@calm/eslint-plugin-react-intl 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@calm/eslint-plugin-react-intl 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@calm/eslint-plugin-react-intl 可以商用吗?

@calm/eslint-plugin-react-intl 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@calm/eslint-plugin-react-intl 的下载量有多少?

根据 npm 官方下载统计,@calm/eslint-plugin-react-intl 在 2026/10/09 – 2026/11/07 这 30 天内被下载 129,756 次,日均约 4,325 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@calm/eslint-plugin-react-intl 还在维护吗?

最新版本 1.4.1 发布于 2020/02/28(6 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/04/19。作者已将其标记为弃用,新项目建议寻找替代方案。