UNPKG

4.43 kBMarkdownView Raw
1# ESLint plugin for React Native
2
3# Project update
4
5Dear users, first of all, thanks for using the plugin! At the moment development activity is low, I've personally not worked with React Native for many years and have little time to continue updating the plugin. I'll do my best to update the plugin to ensure compatibility with new eslint versions, but unfortunately I do not have time to asses new features/pull requests. Thanks for your understanding!
6
7[![Greenkeeper badge](https://badges.greenkeeper.io/Intellicode/eslint-plugin-react-native.svg)](https://greenkeeper.io/)
8
9[![Maintenance Status][status-image]][status-url] [![NPM version][npm-image]][npm-url] [![Coverage Status][coverage-image]][coverage-url]
10
11React Native specific linting rules for ESLint. This repository is structured like (and contains code from) the excellent [eslint-plugin-react](http://github.com/yannickcr/eslint-plugin-react).
12
13# Installation
14
15Install [ESLint](https://www.github.com/eslint/eslint) either locally or globally.
16
17```sh
18$ npm install --save-dev eslint
19```
20
21To make most use of this plugin, its recommended to install [eslint-plugin-react](http://github.com/yannickcr/eslint-plugin-react) in addition to [ESLint](https://www.github.com/eslint/eslint). If you installed `ESLint` globally, you have to install eslint-plugin-react globally too. Otherwise, install it locally.
22
23```sh
24$ npm install --save-dev eslint-plugin-react
25```
26
27Similarly, install eslint-plugin-react-native
28
29```sh
30$ npm install --save-dev eslint-plugin-react-native
31```
32
33# Configuration
34
35Add `plugins` section and specify ESLint-plugin-React (optional) and ESLint-plugin-react-native as a plugin.
36
37```json
38{
39 "plugins": ["react", "react-native"]
40}
41```
42
43If it is not already the case you must also configure `ESLint` to support JSX.
44
45```json
46{
47 "parserOptions": {
48 "ecmaFeatures": {
49 "jsx": true
50 }
51 }
52}
53```
54
55In order to whitelist all _browser-like_ globals, add `react-native/react-native` to your config.
56
57```json
58{
59 "env": {
60 "react-native/react-native": true
61 }
62}
63```
64
65To use another stylesheet providers.
66
67```json
68settings: {
69 'react-native/style-sheet-object-names': ['EStyleSheet', 'OtherStyleSheet', 'PStyleSheet']
70}
71```
72
73Finally, enable all of the rules that you would like to use.
74
75```json
76{
77 "rules": {
78 "react-native/no-unused-styles": 2,
79 "react-native/split-platform-components": 2,
80 "react-native/no-inline-styles": 2,
81 "react-native/no-color-literals": 2,
82 "react-native/no-raw-text": 2,
83 "react-native/no-single-element-style-arrays": 2
84 }
85}
86```
87
88# List of supported rules
89
90- [no-unused-styles](docs/rules/no-unused-styles.md): Detect `StyleSheet` rules which are not used in your React components
91- [sort-styles](docs/rules/sort-styles.md): Require style definitions to be sorted alphabetically
92- [split-platform-components](docs/rules/split-platform-components.md): Enforce using platform specific filenames when necessary
93- [no-inline-styles](docs/rules/no-inline-styles.md): Detect JSX components with inline styles that contain literal values
94- [no-color-literals](docs/rules/no-color-literals.md): Detect `StyleSheet` rules and inline styles containing color literals instead of variables
95- [no-raw-text](docs/rules/no-raw-text.md): Detect raw text outside of `Text` component
96- [no-single-element-style-arrays](docs/rules/no-single-element-style-arrays.md): No style arrays that have 1 element only `<View style={[{height: 10}]}/>`
97
98[npm-url]: https://npmjs.org/package/eslint-plugin-react-native
99[npm-image]: http://img.shields.io/npm/v/eslint-plugin-react-native.svg?style=flat-square
100[coverage-url]: https://coveralls.io/r/Intellicode/eslint-plugin-react-native?branch=master
101[coverage-image]: http://img.shields.io/coveralls/Intellicode/eslint-plugin-react-native/master.svg?style=flat-square
102[status-url]: https://github.com/Intellicode/eslint-plugin-react-native/pulse
103[status-image]: http://img.shields.io/badge/status-maintained-brightgreen.svg?style=flat-square
104
105# Shareable configurations
106
107## All
108
109This plugin also exports an `all` configuration that includes every available rule.
110
111```js
112{
113 "plugins": [
114 /* ... */
115 "react-native"
116 ],
117 "extends": [/* ... */, "plugin:react-native/all"]
118}
119```
120
121**Note**: These configurations will import `eslint-plugin-react-native` and enable JSX in [parser options](http://eslint.org/docs/user-guide/configuring#specifying-parser-options).