Skip to content

Commit 5209eaa

Browse files
committed
docs: automate docs with eslint-doc-generator
1 parent 7fdaedc commit 5209eaa

16 files changed

+1674
-129
lines changed

README.md

+28-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
# ESLint plugin for React Native
12

2-
ESLint plugin for React Native
3-
==============================
4-
5-
# Project update
3+
## Project update
64

75
Dear 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!
86

@@ -12,28 +10,27 @@ Dear users, first of all, thanks for using the plugin! At the moment development
1210

1311
React 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).
1412

15-
# Installation
13+
## Installation
1614

1715
Install [ESLint](https://github.com/eslint/eslint) either locally or globally.
1816

1917
```sh
20-
$ npm install --save-dev eslint
18+
npm install --save-dev eslint
2119
```
2220

2321
To 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://github.com/eslint/eslint). If you installed `ESLint` globally, you have to install eslint-plugin-react globally too. Otherwise, install it locally.
2422

2523
```sh
26-
$ npm install --save-dev eslint-plugin-react
24+
npm install --save-dev eslint-plugin-react
2725
```
2826

2927
Similarly, install eslint-plugin-react-native
3028

31-
3229
```sh
33-
$ npm install --save-dev eslint-plugin-react-native
30+
npm install --save-dev eslint-plugin-react-native
3431
```
3532

36-
# Configuration
33+
## Configuration
3734

3835
Add `plugins` section and specify ESLint-plugin-React (optional) and ESLint-plugin-react-native as a plugin.
3936

@@ -91,15 +88,25 @@ Finally, enable all of the rules that you would like to use.
9188
}
9289
```
9390

94-
# List of supported rules
91+
## List of supported rules
92+
93+
<!-- begin auto-generated rules list -->
9594

96-
* [no-unused-styles](docs/rules/no-unused-styles.md): Detect `StyleSheet` rules which are not used in your React components
97-
* [sort-styles](docs/rules/sort-styles.md): Require style definitions to be sorted alphabetically
98-
* [split-platform-components](docs/rules/split-platform-components.md): Enforce using platform specific filenames when necessary
99-
* [no-inline-styles](docs/rules/no-inline-styles.md): Detect JSX components with inline styles that contain literal values
100-
* [no-color-literals](docs/rules/no-color-literals.md): Detect `StyleSheet` rules and inline styles containing color literals instead of variables
101-
* [no-raw-text](docs/rules/no-raw-text.md): Detect raw text outside of `Text` component
102-
* [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}]}/>`
95+
💼 [Configurations](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations) enabled in.\
96+
🌐 Set in the `all` [configuration](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).\
97+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
98+
99+
| Name                           | Description | 💼 | 🔧 |
100+
| :----------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------- | :- | :- |
101+
| [no-color-literals](docs/rules/no-color-literals.md) | Detect `StyleSheet` rules and inline styles containing color literals instead of variables | 🌐 | |
102+
| [no-inline-styles](docs/rules/no-inline-styles.md) | Detect JSX components with inline styles that contain literal values | 🌐 | |
103+
| [no-raw-text](docs/rules/no-raw-text.md) | Detect raw text outside of `Text` component | 🌐 | |
104+
| [no-single-element-style-arrays](docs/rules/no-single-element-style-arrays.md) | Disallow single element style arrays. These cause unnecessary re-renders as the identity of the array always changes | 🌐 | 🔧 |
105+
| [no-unused-styles](docs/rules/no-unused-styles.md) | Detect `StyleSheet` rules which are not used in your React components | 🌐 | |
106+
| [sort-styles](docs/rules/sort-styles.md) | Require style definitions to be sorted alphabetically | 🌐 | 🔧 |
107+
| [split-platform-components](docs/rules/split-platform-components.md) | Enforce using platform specific filenames when necessary | 🌐 | 🔧 |
108+
109+
<!-- end auto-generated rules list -->
103110

104111
[npm-url]: https://npmjs.org/package/eslint-plugin-react-native
105112
[npm-image]: http://img.shields.io/npm/v/eslint-plugin-react-native.svg?style=flat-square
@@ -115,9 +122,10 @@ Finally, enable all of the rules that you would like to use.
115122

116123
[bettercode-image]: https://bettercodehub.com/edge/badge/Intellicode/eslint-plugin-react-native
117124
[bettercode-url]: https://bettercodehub.com
118-
# Shareable configurations
119125

120-
## All
126+
## Shareable configurations
127+
128+
### All
121129

122130
This plugin also exports an `all` configuration that includes every available rule.
123131

docs/rules/no-color-literals.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
# Detect color literals in styles
2-
When developing UIs, we often find ourselves reusing the same colors in multiple places in the UI.
1+
# Detect `StyleSheet` rules and inline styles containing color literals instead of variables (`react-native/no-color-literals`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
<!-- end auto-generated rule header -->
6+
7+
When developing UIs, we often find ourselves reusing the same colors in multiple places in the UI.
38
If the colors have to be updated, they likely have to be updated across the board. So it's good practice
49
to store the color definitions in variables instead of hardcoding them inside styles. This rule
5-
will detect color properties that have literals (ie strings) as values.
6-
10+
will detect color properties that have literals (ie strings) as values.
11+
712
The rule looks at all properties that contain `color` (case-insensitive) in their name
813
in either `StyleSheet` definitions or JSX properties that have `style` in their name.
914

@@ -51,7 +56,6 @@ The following patterns are considered warnings:
5156
});
5257
```
5358

54-
5559
The following patterns are not considered warnings:
5660

5761
```js

docs/rules/no-inline-styles.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# Detect inline styles in components
2-
It's (subjectively) good practice to separate styles from the view layout, when possible.
1+
# Detect JSX components with inline styles that contain literal values (`react-native/no-inline-styles`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
<!-- end auto-generated rule header -->
6+
7+
It's (subjectively) good practice to separate styles from the view layout, when possible.
38
This rule detects inline style objects when they contain literal values. If inline styles only contain
4-
variable values, the style is considered acceptable because it's sometimes necessary to set styles
9+
variable values, the style is considered acceptable because it's sometimes necessary to set styles
510
based on `state` or `props`.
611

712
## Rule Details
@@ -27,13 +32,15 @@ const Hello = React.createClass({
2732
```
2833

2934
The following pattern is not considered a warning:
35+
3036
```js
3137
const Hello = React.createClass({
3238
render: function() {
3339
return <Text style={styles.name}>Hello {this.props.name}</Text>;
3440
}
3541
});
3642
```
43+
3744
Any attribute that contains the word `style` is checked for inline object literals. Both of the following
3845
are considered warnings:
3946

docs/rules/no-raw-text.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Detect raw text outside of Text component
1+
# Detect raw text outside of `Text` component (`react-native/no-raw-text`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
<!-- end auto-generated rule header -->
6+
27
All strings in React Native should be wrapped with a Text component.
38

49
## Rule Details
@@ -25,6 +30,8 @@ const text = 'some text';
2530
<View><Text>{`${text}`}</Text></View>
2631
```
2732

28-
#### This rule has an object option:
33+
## Options
34+
35+
This rule has an object option:
2936

3037
- "skip" – allow to skip checking for the array of custom components

docs/rules/no-single-element-style-arrays.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# No Single Element Style Arrays are allowed
1+
# Disallow single element style arrays. These cause unnecessary re-renders as the identity of the array always changes (`react-native/no-single-element-style-arrays`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6+
7+
<!-- end auto-generated rule header -->
28

39
These cause unnecessary re-renders as each time the array's identity changes.
410

docs/rules/no-unused-styles.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Detect unused StyleSheet rules in React components
1+
# Detect `StyleSheet` rules which are not used in your React components (`react-native/no-unused-styles`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
<!-- end auto-generated rule header -->
6+
27
When working on a component over a longer period of time, you could end up with unused StyleSheet rules that slipped in over time but are forgotten as you continue to improve your UX/UI design.
38

49
## Rule Details
@@ -18,6 +23,7 @@ const Hello = React.createClass({
1823
```
1924

2025
The following patterns are not considered warnings:
26+
2127
```js
2228
const styles = StyleSheet.create({
2329
name: {}
@@ -29,6 +35,7 @@ const Hello = React.createClass({
2935
}
3036
});
3137
```
38+
3239
The most common case.
3340

3441
```js
@@ -44,6 +51,7 @@ const Hello = React.createClass({
4451
}
4552
});
4653
```
54+
4755
Style rules referenced in a Style array are marked as used.
4856

4957
```js
@@ -57,6 +65,7 @@ const Hello = React.createClass({
5765
}
5866
});
5967
```
68+
6069
Style rules referenced in a conditional and logical expressions are marked as used.
6170

6271
```js
@@ -95,6 +104,7 @@ const Hello = React.createClass({
95104
}
96105
});
97106
```
107+
98108
Rules are also marked as used when they are used in tags that contain the word `style`.
99109

100110
```js
@@ -113,11 +123,13 @@ const Welcome = React.createClass({
113123
}
114124
});
115125
```
126+
116127
Usage is tracked over multiple components in the same file.
117128

118129
```js
119130
const styles = StyleSheet.create({
120131
text: {}
121132
});
122133
```
134+
123135
There should be at least one component, so centralized `StyleSheets` are not checked for unused rules.

docs/rules/sort-styles.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# Require StyleSheet keys to be sorted
1+
# Require style definitions to be sorted alphabetically (`react-native/sort-styles`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6+
7+
<!-- end auto-generated rule header -->
8+
29
It's like [sort-keys](https://eslint.org/docs/rules/sort-keys), but just for React Native styles.
310

411
Keeping your style definitions sorted is a common convention that helps with readability. This rule lets you enforce an ascending (default) or descending alphabetical order for both "class names" and style properties.

docs/rules/split-platform-components.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
# Enforce using platform specific filenames when necessary
1+
# Enforce using platform specific filenames when necessary (`react-native/split-platform-components`)
2+
3+
💼 This rule is enabled in the 🌐 `all` [config](https://github.com/Intellicode/eslint-plugin-react-native#shareable-configurations).
4+
5+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6+
7+
<!-- end auto-generated rule header -->
8+
29
When working on a project that supports both Android and IOS, you have to make sure that you
310
use platform specific filenames when you use platform specific components to produce the correct
411
bundle per platform.
512

613
The following patterns are considered warnings:
714

815
filename: Hello.js
16+
917
```js
1018
const React = require('react-native');
1119
const {
@@ -20,6 +28,7 @@ const Hello = React.createClass({
2028
```
2129

2230
filename: Hello.js
31+
2332
```js
2433
const React = require('react-native');
2534
const {
@@ -34,6 +43,7 @@ const Hello = React.createClass({
3443
```
3544

3645
Any filename
46+
3747
```js
3848
const React = require('react-native');
3949
const {
@@ -53,6 +63,7 @@ const Hello = React.createClass({
5363
```
5464

5565
Using `import` declaration pattern: Hello.js
66+
5667
```js
5768
import React from 'react'
5869
import { ActivityIndicatiorIOS } from 'react-native'
@@ -65,6 +76,7 @@ export default function Hello() {
6576
The following patterns are not considered warnings:
6677

6778
filename: Hello.ios.js
79+
6880
```js
6981
const React = require('react-native');
7082
const {
@@ -79,6 +91,7 @@ const Hello = React.createClass({
7991
```
8092

8193
filename: Hello.android.js
94+
8295
```js
8396
const React = require('react-native');
8497
const {
@@ -93,6 +106,7 @@ const Hello = React.createClass({
93106
```
94107

95108
Using `import` declaration pattern: Hello.ios.js
109+
96110
```js
97111
import React from 'react'
98112
import { ActivityIndicatiorIOS } from 'react-native'

lib/rules/no-color-literals.js

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const create = Components.detect((context) => {
5757

5858
module.exports = {
5959
meta: {
60+
docs: {
61+
description: 'Detect `StyleSheet` rules and inline styles containing color literals instead of variables',
62+
},
6063
schema: [],
6164
},
6265
create,

lib/rules/no-inline-styles.js

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const create = Components.detect((context) => {
4444

4545
module.exports = {
4646
meta: {
47+
docs: {
48+
description: 'Detect JSX components with inline styles that contain literal values',
49+
},
4750
schema: [],
4851
},
4952
create,

lib/rules/no-raw-text.js

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ function create(context) {
9090

9191
module.exports = {
9292
meta: {
93+
docs: {
94+
description: 'Detect raw text outside of `Text` component',
95+
},
9396
schema: [
9497
{
9598
type: 'object',

lib/rules/no-unused-styles.js

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ const create = Components.detect((context, components) => {
6464

6565
module.exports = {
6666
meta: {
67+
docs: {
68+
description: 'Detect `StyleSheet` rules which are not used in your React components',
69+
},
6770
schema: [],
6871
},
6972
create,

lib/rules/sort-styles.js

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ function create(context) {
134134

135135
module.exports = {
136136
meta: {
137+
docs: {
138+
description: 'Require style definitions to be sorted alphabetically',
139+
},
137140
fixable: 'code',
138141
schema: [
139142
{

lib/rules/split-platform-components.js

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ function create(context) {
7979

8080
module.exports = {
8181
meta: {
82+
docs: {
83+
description: 'Enforce using platform specific filenames when necessary',
84+
},
8285
fixable: 'code',
8386
schema: [{
8487
type: 'object',

0 commit comments

Comments
 (0)