yannickcr/eslint-plugin-react


React specific linting rules for ESLint

License: MIT

Language: JavaScript

Keywords: development, ecmascript, eslint, javascript, lint, react


ESLint-plugin-React

Maintenance Status NPM version Build Status Build Status Dependency Status Coverage Status Code Climate

React specific linting rules for ESLint

Installation

Install ESLint either locally or globally.

$ npm install eslint --save-dev

If you installed ESLint globally, you have to install React plugin globally too. Otherwise, install it locally.

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

Configuration

Use our preset to get reasonable defaults:

  "extends": [
    "eslint:recommended",
    "plugin:react/recommended"
  ]

You should also specify settings that will be shared across all the plugin rules. (More about eslint shared settings)

{
  "settings": {
    "react": {
      "createClass": "createReactClass", // Regex for Component Factory to use,
                                         // default to "createReactClass"
      "pragma": "React",  // Pragma to use, default to "React"
      "version": "detect", // React version. "detect" automatically picks the version you have installed.
                           // You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
                           // default to latest and warns if missing
                           // It will default to "detect" in the future
      "flowVersion": "0.53" // Flow version
    },
    "propWrapperFunctions": [
        // The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
        "forbidExtraProps",
        {"property": "freeze", "object": "Object"},
        {"property": "myFavoriteWrapper"}
    ],
    "linkComponents": [
      // Components used as alternatives to <a> for linking, eg. <Link to={ url } />
      "Hyperlink",
      {"name": "Link", "linkAttribute": "to"}
    ]
  }
}

If you do not use a preset you will need to specify individual rules and add extra configuration.

Add "react" to the plugins section.

{
  "plugins": [
    "react"
  ]
}

Enable JSX support.

With ESLint 2+

{
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    }
  }
}

Enable the rules that you would like to use.

  "rules": {
    "react/jsx-uses-react": "error",
    "react/jsx-uses-vars": "error",
  }

List of supported rules

JSX-specific rules

Other useful plugins

Shareable configurations

Recommended

This plugin exports a recommended configuration that enforces React good practices.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["eslint:recommended", "plugin:react/recommended"]
}

See ESLint documentation for more information about extending configuration files.

The rules enabled in this configuration are:

All

This plugin also exports an all configuration that includes every available rule. This pairs well with the eslint:all rule.

{
  "plugins": [
    "react"
  ],
  "extends": ["eslint:all", "plugin:react/all"]
}

Note: These configurations will import eslint-plugin-react and enable JSX in parser options.

License

ESLint-plugin-React is licensed under the MIT License.

Project Statistics

Sourcerank 23
Repository Size 3.79 MB
Stars 5,221
Forks 1,352
Watchers 84
Open issues 437
Dependencies 15
Contributors 297
Tags 134
Created
Last updated
Last pushed

Top Contributors See all

Yannick Croissant Jordan Harband Joachim Seminck Joe Lencioni Jacky Ho Alex Zherdev Joshua Stiefer Patrick Hayes Sergei Startsev DianaSuvorova Mark Allen David Petersen Caleb Morris Adrian Yak Jun Xiang Roy Sutton Rafał Ruciński Yevgeny Petukhov Brett Higgins Jørgen Aaberg

Packages Referencing this Repo

eslint-plugin-react
React specific linting rules for ESLint
Latest release 7.13.0 - Updated - 5.22K stars
@zaibot/eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.9.1 - Published - 5.22K stars
eslint-plugin-react-ep
React specific linting rules for ESLint
Latest release 6.9.1 - Published - 5.22K stars
eslint-plugin-reactzaibot
React specific linting rules for ESLint
Latest release 6.9.6 - Updated - 5.22K stars
org.webjars.npm:eslint-plugin-react
WebJar for eslint-plugin-react
Latest release 6.2.0 - Published - 5.22K stars
@kentcdodds/eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.10.0-beta.0 - Published - 5.22K stars
zaibot-eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.9.2 - Published - 5.22K stars
eslint-plugin-react
WebJar for eslint-plugin-react
Latest release 6.2.0 - Published - 5.22K stars
eslint-plugin-react-zaibot
React specific linting rules for ESLint
Latest release 6.9.3 - Published - 5.22K stars

Recent Tags See all

v7.13.0 May 03, 2019
v7.12.4 January 17, 2019
v7.12.3 January 04, 2019
v7.12.2 January 02, 2019
v7.12.1 January 01, 2019
v7.12.0 December 28, 2018
v7.11.1 August 14, 2018
v7.11.0 August 13, 2018
v7.10.0 June 25, 2018
v7.9.1 June 04, 2018
v7.9.0 June 03, 2018
v7.8.2 May 13, 2018
v7.8.1 May 11, 2018
v7.8.0 May 11, 2018
v7.8.0-rc.0 May 10, 2018

Interesting Forks See all

infernojs/eslint-plugin-inferno
Inferno specific linting rules for ESLint
JavaScript - MIT - Last pushed - 10 stars - 6 forks
thepechinator/eslint-plugin-react
React specific linting rules for ESLint
JavaScript - MIT - Last pushed - 1 stars
Khan/eslint-plugin-react
React specific linting rules for ESLint
JavaScript - MIT - Last pushed - 1 stars
jacklovepdf/eslint-plugin-react
React specific linting rules for ESLint
JavaScript - Updated - 1 stars
niilante/eslint-plugin-react
React specific linting rules for ESLint
JavaScript - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-05-03 07:31:20 UTC

Login to resync this repository