@nekogaming/eslint-config-react-native
v4.1.1
Published
Pluggable ESLint config for React Native that you can import, extend and override
Downloads
1
Maintainers
Readme
eslint-config-react-native
Usage
In your js project directory:
npm install --save-dev eslint-config-react-native
And in your .eslintrc.yaml
:
extends:
- react-native
Alternatively, 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 husky
And 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: true
enables browser features and global variables
plugins:
- react
- react-native
provides React, JSX and React Native specific rules
extends:
- esnext
- plugin:react/recommended
enables jsx
parsing, includes config and rules from eslint-config-esnext and the following react-specific recommended rules:
react/display-name
: prevent missingdisplayName
in 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.state
react/no-is-mounted
: prevent usage ofisMounted
react/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 missingReact
when using JSXreact/require-render-return
: prevent missingreturn
inrender()
rules:
selected from here, configured to:
react-native/no-color-literals
: detectStyleSheet
rules 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 unusedStyleSheet
rulesreact-native/split-platform-components
: enforce using platform specific filenames when necessaryreact/jsx-boolean-value
: prefer shorthand if an attribute has atrue
value in JSXreact/jsx-handler-names
: enforce event handler naming conventions in JSXreact/jsx-key
: validate JSX haskey
prop 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 ofdangerouslySetInnerHTML
react/no-did-mount-set-state
: prevent usage ofsetState
incomponentDidMount
, but allow inside callbacksreact/no-did-update-set-state
: prevent usage ofsetState
incomponentDidUpdate
, but allow inside callbacksreact/no-find-dom-node
: Prevent usage offindDOMNode
react/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 inref
attributereact/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