React specific linting rules for ESLint
Перейти к файлу
Yannick Croissant b9cfdd6fcc Update CHANGELOG and bump version 2017-03-20 22:46:54 +01:00
docs/rules Revert "[Fix] jsx-indent with tabs (fixes #1057)" 2017-03-20 22:46:45 +01:00
lib Revert "[Fix] jsx-indent with tabs (fixes #1057)" 2017-03-20 22:46:45 +01:00
tests Revert "[Fix] jsx-indent with tabs (fixes #1057)" 2017-03-20 22:46:45 +01:00
.editorconfig Update config files 2014-12-29 11:23:15 +01:00
.eslintignore Update config files 2014-12-29 11:23:15 +01:00
.eslintrc [Fix] Never call Object prototype builtins directly. 2016-11-14 14:03:12 -08:00
.gitignore Update config files 2014-12-29 11:23:15 +01:00
.travis.yml [Tests] require tests to pass down to node 0.10; add node 7 2017-01-21 02:07:52 -08:00
CHANGELOG.md Update CHANGELOG and bump version 2017-03-20 22:46:54 +01:00
LICENSE Initial commit 2014-12-16 00:44:14 +01:00
README.md Merge pull request #890 from kentor/forbid-elements 2017-02-15 10:03:52 -08:00
appveyor.yml [Tests] [appveyor] drop support for pre-node-4, add node 6. 2016-07-06 09:17:37 -07:00
index.js Merge pull request #890 from kentor/forbid-elements 2017-02-15 10:03:52 -08:00
package.json Update CHANGELOG and bump version 2017-03-20 22:46:54 +01:00

README.md

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

Add plugins section and specify ESLint-plugin-React as a plugin.

{
  "plugins": [
    "react"
  ]
}

You can also specify some settings that will be shared across all the plugin rules.

{
  "settings": {
    "react": {
      "createClass": "createClass", // Regex for Component Factory to use, default to "createClass"
      "pragma": "React",  // Pragma to use, default to "React"
      "version": "15.0" // React version, default to the latest React stable release
    }
  }
}

If it is not already the case you must also configure ESLint to support JSX.

With ESLint 1.x.x:

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

With ESLint 2.x.x or 3.x.x:

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

Finally, enable all of the rules that you would like to use. Use our preset to get reasonable defaults quickly, and/or choose your own:

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

List of supported rules

JSX-specific rules

Other useful plugins

Shareable configurations

This plugin exports a recommended configuration that enforce 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.