React specific linting rules for ESLint
React specific linting rules for ESLint
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
Add plugins section and specify ESLint-plugin-React as a plugin.
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" "version": "0.14.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:
With ESLint 2.x.x:
Finally, enable all of the rules that you would like to use.
The plugin has a recommended configuration that enforces React good practices.
displayName in a React component definitionsetState in componentDidMountsetState in componentDidUpdatethis.stateisMountedsetStateref attribute.React when using JSX.bind() and arrow functions in JSX propsIf you're searching for React Native specific linting rules, check out eslint-plugin-react-native.
This plugin exports a recommended configuration that enforce React good practices.
To enable this configuration use the extends property in your .eslintrc config file:
"plugins": "react" "extends": "eslint:recommended" "plugin:react/recommended"
See ESLint documentation for more information about extending configuration files.
The rules enabled in this configuration are:
allow-in-func optionallow-in-func optionNote: This configuration will also enable JSX in parser options.
ESLint-plugin-React is licensed under the MIT License.