eslint-config-react-native
v4.1.0
Published
Pluggable ESLint config for React Native that you can import, extend and override
Maintainers
Readme
Pluggable ESLint config for React Native that you can import, extend and override
React Native: Safety Checks and Best Practices with a bias toward code concision / brevity
Usage
In your js project directory:
npm install --save-dev eslint-config-react-nativeAnd in your .eslintrc.yaml:
extends:
- react-nativeAlternatively, in your .eslintrc.js or .eslintrc.json:
{
"extends": ["react-native"]
}To add a git-hook to your commits, consider using husky
npm install --save-dev huskyAnd in your package.json:
"scripts": {
"precommit": "eslint ."
}Config
This config is biased and opinionated, and errs on the side of too many rules instead of too few. Think of this as a superset of your repo's lint config, and discard what you don't like in it. It's easy to override and disable the rules you find inconvenient.
env:
browser: trueenables browser features and global variables
plugins:
- react
- react-nativeprovides React, JSX and React Native specific rules
extends:
- esnext
- plugin:react/recommendedenables jsx parsing, includes config and rules from eslint-config-esnext and the following react-specific recommended rules:
react/display-name: prevent missingdisplayNamein a React component definitionreact/jsx-no-duplicate-props: prevent duplicate properties in JSX componentsreact/jsx-no-undef: disallow undeclared variables as JSX componentsreact/jsx-uses-react: prevent React from being marked as unused in a file using JSXreact/jsx-uses-vars: prevent variables used in JSX to be incorrectly marked as unusedreact/no-deprecated: prevent usage of deprecated methodsreact/no-direct-mutation-state: prevent direct mutation ofthis.statereact/no-is-mounted: prevent usage ofisMountedreact/no-unknown-property: prevent usage of unknown DOM propertyreact/prop-types: prevent missing props validation in a React component definitionreact/react-in-jsx-scope: prevent missingReactwhen using JSXreact/require-render-return: prevent missingreturninrender()
rules:selected from here, configured to:
react-native/no-color-literals: detectStyleSheetrules and inline styles containing color literals instead of variablesreact-native/no-inline-styles: detect JSX components with inline styles that contain literal valuesreact-native/no-unused-styles: detect unusedStyleSheetrulesreact-native/split-platform-components: enforce using platform specific filenames when necessaryreact/jsx-boolean-value: prefer shorthand if an attribute has atruevalue in JSXreact/jsx-handler-names: enforce event handler naming conventions in JSXreact/jsx-key: validate JSX haskeyprop when in array or iterator; set to warn onlyreact/jsx-no-bind: prevent usage of.bind()and arrow functions in JSX props; set to warn onlyreact/jsx-pascal-case: enforce PascalCase for user-defined JSX componentsreact/jsx-wrap-multilines: prevent missing parentheses around multiline JSXreact/no-danger: prevent usage ofdangerouslySetInnerHTMLreact/no-did-mount-set-state: prevent usage ofsetStateincomponentDidMount, but allow inside callbacksreact/no-did-update-set-state: prevent usage ofsetStateincomponentDidUpdate, but allow inside callbacksreact/no-find-dom-node: Prevent usage offindDOMNodereact/no-multi-comp: prevent multiple component definitions per file, apart from stateless functional componentsreact/no-render-return-value: prevent usage of the return value ofReactDOM.render()react/no-string-refs: prevent using string references inrefattributereact/no-unused-prop-types: prevent definitions of unused prop typesreact/prefer-es6-class: enforce ES5 or ES6 class for React Componentsreact/prefer-stateless-function: enforce stateless React Components to be written as a pure function
