Skip to content

Latest commit

 

History

History
180 lines (138 loc) · 9.07 KB

README.md

File metadata and controls

180 lines (138 loc) · 9.07 KB

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

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

$ npm install eslint-plugin-react

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": {
      "pragma": "React" // Pragma to use, default to "React"
    }
  }
}

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:

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

Finally, enable all of the rules that you would like to use.

List of supported rules

JSX-specific rules

React Native rules

If you're searching for React Native specific linting rules, check out eslint-plugin-react-native.

Recommended configuration

This plugin export a recommended configuration that enforce React good practices.

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

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

See ESLint documentation for more information about extending configuration files.

The rules enabled in this configuration are:

Note: This configuration will also enable JSX in parser options.

License

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