eslint-plugin-react-extended
v0.0.8
Published
React specific linting rules for ESLint
Downloads
223
Maintainers
Readme
ESLint-plugin-React-extended
React specific linting rules for ESLint
Installation
Install ESLint either locally or globally. (Note that locally, per project, is strongly preferred)
$ yarn add eslint --dev
If you installed ESLint
globally, you have to install React plugin globally too. Otherwise, install it locally.
$ yarn add eslint-plugin-react-extended --dev
Configuration
Use our preset to get reasonable defaults:
"extends": [
"eslint:recommended",
"plugin:react-extended/recommended"
]
You should also specify settings that will be shared across all the plugin rules. (More about eslint shared settings)
{
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React", // Pragma to use, default to "React"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
"flowVersion": "0.53" // Flow version
},
"propWrapperFunctions": [
// The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
"forbidExtraProps",
{"property": "freeze", "object": "Object"},
{"property": "myFavoriteWrapper"}
],
"linkComponents": [
// Components used as alternatives to <a> for linking, eg. <Link to={ url } />
"Hyperlink",
{"name": "Link", "linkAttribute": "to"}
]
}
}
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-extended"
]
}
Enable JSX support.
With ESLint 2+
{
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
}
}
Enable the rules that you would like to use.
"rules": {
"react-extended/jsx-no-random-key": "error",
}
List of supported rules
JSX-specific rules
- react-extended/jsx-no-random-key: Prevent usage of random value for
key
prop
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-extended/recommended"]
}
See ESLint documentation for more information about extending configuration files.
The rules enabled in this configuration are:
- react-extended/jsx-no-random-key: Prevent usage of random value for
key
prop
All
This plugin also exports an all
configuration that includes every available rule.
This pairs well with the eslint:all
rule.
{
"plugins": [
"react-extended"
],
"extends": ["eslint:all", "plugin:react-extended/all"]
}
Note: These configurations will import eslint-plugin-react-extended
and enable JSX in parser options.
License
ESLint-plugin-React-extended is licensed under the MIT License.