Socket
Book a DemoInstallSign in
Socket

eslint-plugin-react-intl-format

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react-intl-format

Linter for React-Intl integration

Source
npmnpm
Version
1.1.4
Version published
Weekly downloads
21
2000%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-react-intl-format

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.

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

FormattedMessage validation

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
  • defaultMessage and id attributes cannot be empty

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-react-intl-format:

$ npm install eslint-plugin-react-intl-format --save-dev

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

Usage

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

{
    "plugins": [
        "react-intl-format"
    ]
}

Then configure the rules you want to use under the rules section. Currently there's just one rule: 'missing-formatted-message'.

{
    "rules": {
        "react-intl-format/missing-formatted-message": [2, { "noTrailingWhitespace": true, "ignoreLinks": true }],
        "react-intl-format/missing-attribute": [2, { "noTrailingWhitespace": true }],
        "react-intl-format/missing-values": 2
    }
}

Supported Rules

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

Keywords

eslint

FAQs

Package last updated on 28 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts