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 Dependency Status Coverage Status Code Climate Tidelift

React specific linting rules for ESLint

Installation

Install ESLint either locally or globally. (Note that locally, per project, is strongly preferred)

$ 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 4.36 MB
Stars 5,840
Forks 1,580
Watchers 90
Open issues 478
Dependencies 22
Contributors 320
Tags 141
Created
Last updated
Last pushed

Top Contributors See all

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

Packages Referencing this Repo

org.webjars.npm:eslint-plugin-react
WebJar for eslint-plugin-react
Latest release 6.2.0 - Published - 5.84K stars
eslint-plugin-react-zaibot
React specific linting rules for ESLint
Latest release 6.9.3 - Published - 5.84K stars
eslint-plugin-react
React specific linting rules for ESLint
Latest release 7.16.0 - Updated - 5.84K stars
eslint-plugin-react-ep
React specific linting rules for ESLint
Latest release 6.9.1 - Published - 5.84K stars
zaibot-eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.9.2 - Published - 5.84K stars
eslint-plugin-react-native-no-get-item-layout-prop-on-virtualized-list
Checks that the `getItemLayout` prop isn't being used on `VirtualizedList`, `FlatList`, or `Secti...
Latest release 1.0.1 - Updated - 5.84K stars
@hypnosphi/eslint-plugin-react
React specific linting rules for ESLint
Latest release 7.14.3 - Published - 5.84K stars
no-get-item-layout-prop-on-virtualized-list
Checks that the broken getItemLayout prop isn't added
Latest release 1.0.0 - Published - 5.84K stars
@kentcdodds/eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.10.0-beta.0 - Published - 5.84K stars
eslint-plugin-reactzaibot
React specific linting rules for ESLint
Latest release 6.9.6 - Updated - 5.84K stars
@zaibot/eslint-plugin-react
React specific linting rules for ESLint
Latest release 6.9.1 - Published - 5.84K stars

Recent Tags See all

v7.16.0 October 04, 2019
v7.15.1 October 01, 2019
v7.15.0 October 01, 2019
v7.14.3 July 22, 2019
v7.14.2 June 24, 2019
v7.14.1 June 24, 2019
v7.14.0 June 23, 2019
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

Interesting Forks See all

infernojs/eslint-plugin-inferno
Inferno specific linting rules for ESLint
JavaScript - MIT - Last pushed - 12 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-10-17 08:38:57 UTC

Login to resync this repository