JSPM

  • Created
  • Published
  • Downloads 23753055
  • Score
    100M100P100Q217245F
  • License MIT

React specific linting rules for ESLint

Package Exports

  • eslint-plugin-react
  • eslint-plugin-react/lib/rules/button-has-type
  • eslint-plugin-react/lib/rules/forbid-component-props
  • eslint-plugin-react/lib/rules/forbid-dom-props
  • eslint-plugin-react/lib/rules/forbid-elements
  • eslint-plugin-react/lib/rules/forbid-foreign-prop-types
  • eslint-plugin-react/lib/rules/jsx-boolean-value
  • eslint-plugin-react/lib/rules/jsx-child-element-spacing
  • eslint-plugin-react/lib/rules/jsx-closing-tag-location
  • eslint-plugin-react/lib/rules/jsx-curly-brace-presence
  • eslint-plugin-react/lib/rules/jsx-curly-spacing
  • eslint-plugin-react/lib/rules/jsx-equals-spacing
  • eslint-plugin-react/lib/rules/jsx-filename-extension
  • eslint-plugin-react/lib/rules/jsx-indent
  • eslint-plugin-react/lib/rules/jsx-indent-props
  • eslint-plugin-react/lib/rules/jsx-max-depth
  • eslint-plugin-react/lib/rules/jsx-no-bind
  • eslint-plugin-react/lib/rules/jsx-no-duplicate-props
  • eslint-plugin-react/lib/rules/jsx-no-literals
  • eslint-plugin-react/lib/rules/jsx-no-target-blank
  • eslint-plugin-react/lib/rules/jsx-no-undef
  • eslint-plugin-react/lib/rules/jsx-pascal-case
  • eslint-plugin-react/lib/rules/jsx-props-no-multi-spaces
  • eslint-plugin-react/lib/rules/jsx-sort-props
  • eslint-plugin-react/lib/rules/jsx-tag-spacing
  • eslint-plugin-react/lib/rules/jsx-uses-react
  • eslint-plugin-react/lib/rules/jsx-uses-vars
  • eslint-plugin-react/lib/rules/no-array-index-key
  • eslint-plugin-react/lib/rules/no-children-prop
  • eslint-plugin-react/lib/rules/no-danger
  • eslint-plugin-react/lib/rules/no-did-mount-set-state
  • eslint-plugin-react/lib/rules/no-did-update-set-state
  • eslint-plugin-react/lib/rules/no-direct-mutation-state
  • eslint-plugin-react/lib/rules/no-find-dom-node
  • eslint-plugin-react/lib/rules/no-is-mounted
  • eslint-plugin-react/lib/rules/no-set-state
  • eslint-plugin-react/lib/rules/no-string-refs
  • eslint-plugin-react/lib/rules/no-unescaped-entities
  • eslint-plugin-react/lib/rules/no-unknown-property
  • eslint-plugin-react/lib/rules/no-unsafe
  • eslint-plugin-react/lib/rules/no-unused-prop-types
  • eslint-plugin-react/lib/rules/no-will-update-set-state
  • eslint-plugin-react/lib/rules/prefer-es6-class
  • eslint-plugin-react/lib/rules/prop-types
  • eslint-plugin-react/lib/rules/react-in-jsx-scope
  • eslint-plugin-react/lib/rules/require-optimization
  • eslint-plugin-react/lib/rules/self-closing-comp
  • eslint-plugin-react/lib/rules/void-dom-elements-no-children
  • eslint-plugin-react/lib/util/Components
  • eslint-plugin-react/lib/util/annotations
  • eslint-plugin-react/lib/util/ast
  • eslint-plugin-react/lib/util/docsUrl
  • eslint-plugin-react/lib/util/getTokenBeforeClosingBracket
  • eslint-plugin-react/lib/util/pragma
  • eslint-plugin-react/lib/util/props
  • eslint-plugin-react/lib/util/variable
  • eslint-plugin-react/lib/util/version

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

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.