React specific linting rules for ESLint (evacuated from NSA/Microsoft github)

Yannick Croissant fee2d1a02f Fix crash in no-unused-prop-types when encountering mixed union and intersection flow types (fixes #1806) 5 years ago
docs 7c5b8c4e7e [Docs] Typo fixes in jsx-no-target-blank 5 years ago
lib fee2d1a02f Fix crash in no-unused-prop-types when encountering mixed union and intersection flow types (fixes #1806) 5 years ago
tests fee2d1a02f Fix crash in no-unused-prop-types when encountering mixed union and intersection flow types (fixes #1806) 5 years ago
.editorconfig f52552f83f Update config files 9 years ago
.eslintignore a36b1f9c53 chore: rm node_modules from eslintignore. 6 years ago
.eslintrc fdb824ee1b Update .eslintrc 6 years ago
.gitignore 0c3638015b Only apps should have lockfiles. 6 years ago
.npmrc 0c3638015b Only apps should have lockfiles. 6 years ago
.travis.yml cb4d21ea61 Run tests against different ESLint versions on Travis 5 years ago
CHANGELOG.md ac10288576 Update CHANGELOG and bump version 5 years ago
CONTRIBUTING.md b4d76e968a Add CONTRIBUTING.md 6 years ago
LICENSE d406540f6a Initial commit 9 years ago
README.md 05a06076b3 Merge pull request #1755 from ThiefMaster/jsx-props-no-multi-spaces 5 years ago
appveyor.yml 230b0adee4 [Tests] fix appveyor 6 years ago
index.js 64ef4b8ccb Add jsx-props-no-multi-spaces rule 6 years ago
package.json ac10288576 Update CHANGELOG and bump version 5 years ago

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

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.

{
  "settings": {
    "react": {
      "createClass": "createReactClass", // Regex for Component Factory to use,
                                         // default to "createReactClass"
      "pragma": "React",  // Pragma to use, default to "React"
      "version": "15.0", // React version, default to the latest React stable release
      "flowVersion": "0.53" // Flow version
    },
    "propWrapperFunctions": [ "forbidExtraProps" ] // The names of any functions used to wrap the
                                                   // propTypes object, e.g. `forbidExtraProps`.
                                                   // If this isn't set, any propTypes wrapped in
                                                   // a function will be skipped.
  }
}

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.