Skip to content

Commit a2b61ed

Browse files
authored
Merge branch 'master' into allow-wrapped-pure-components
2 parents 4e8e86a + fd90dae commit a2b61ed

37 files changed

+538
-152
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
102102
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
103103
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
104104
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
105+
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
105106
* [react/prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components
106107
* [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless React Components to be written as a pure function
107108
* [react/prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition

docs/rules/display-name.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Hello = React.createClass({
2929

3030
```js
3131
...
32-
"display-name": [<enabled>, { "ignoreTranspilerName": <boolean> }]
32+
"react/display-name": [<enabled>, { "ignoreTranspilerName": <boolean> }]
3333
...
3434
```
3535

docs/rules/forbid-component-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The following patterns are not considered warnings:
3535

3636
```js
3737
...
38-
"forbid-component-props": [<enabled>, { "forbid": [<string>] }]
38+
"react/forbid-component-props": [<enabled>, { "forbid": [<string>] }]
3939
...
4040
```
4141

docs/rules/forbid-elements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This rule checks all JSX elements and `React.createElement` calls and verifies t
1010

1111
```js
1212
...
13-
"forbid-elements": [<enabled>, { "forbid": [<string|object>] }]
13+
"react/forbid-elements": [<enabled>, { "forbid": [<string|object>] }]
1414
...
1515
```
1616

docs/rules/jsx-closing-bracket-location.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ There are two ways to configure this rule.
3939
The first form is a string shortcut corresponding to the `location` values specified below. If omitted, it defaults to `"tag-aligned"`.
4040

4141
```js
42-
"jsx-closing-bracket-location": <enabled> // -> [<enabled>, "tag-aligned"]
43-
"jsx-closing-bracket-location": [<enabled>, "<location>"]
42+
"react/jsx-closing-bracket-location": <enabled> // -> [<enabled>, "tag-aligned"]
43+
"react/jsx-closing-bracket-location": [<enabled>, "<location>"]
4444
```
4545

4646
The second form allows you to distinguish between non-empty and self-closing tags. Both properties are optional, and both default to `"tag-aligned"`. You can also disable the rule for one particular type of tag by setting the value to `false`.
4747

4848
```js
49-
"jsx-closing-bracket-location": [<enabled>, {
49+
"react/jsx-closing-bracket-location": [<enabled>, {
5050
"nonEmpty": "<location>" || false,
5151
"selfClosing": "<location>" || false
5252
}]

docs/rules/jsx-curly-spacing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ There are two main options for the rule:
2020
Depending on your coding conventions, you can choose either option by specifying it in your configuration:
2121

2222
```json
23-
"jsx-curly-spacing": [2, "always"]
23+
"react/jsx-curly-spacing": [2, "always"]
2424
```
2525

2626
#### never
@@ -68,7 +68,7 @@ The following patterns are not warnings:
6868
By default, braces spanning multiple lines are allowed with either setting. If you want to disallow them you can specify an additional `allowMultiline` property with the value `false`:
6969

7070
```json
71-
"jsx-curly-spacing": [2, "never", {"allowMultiline": false}]
71+
"react/jsx-curly-spacing": [2, "never", {"allowMultiline": false}]
7272
```
7373

7474
When `"never"` is used and `allowMultiline` is `false`, the following patterns are considered warnings:
@@ -112,7 +112,7 @@ The following patterns are not warnings:
112112
You can specify an additional `spacing` property that is an object with the following possible values:
113113

114114
```json
115-
"jsx-curly-spacing": [2, "always", {"spacing": {
115+
"react/jsx-curly-spacing": [2, "always", {"spacing": {
116116
"objectLiterals": "never"
117117
}}]
118118
```

docs/rules/jsx-equals-spacing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ There are two options for the rule:
1818
Depending on your coding conventions, you can choose either option by specifying it in your configuration:
1919

2020
```json
21-
"jsx-equals-spacing": [2, "always"]
21+
"react/jsx-equals-spacing": [2, "always"]
2222
```
2323

2424
#### never

docs/rules/jsx-handler-names.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The following patterns are not considered warnings:
2828

2929
```js
3030
...
31-
"jsx-handler-names": [<enabled>, {
31+
"react/jsx-handler-names": [<enabled>, {
3232
"eventHandlerPrefix": <eventHandlerPrefix>,
3333
"eventHandlerPropPrefix": <eventHandlerPropPrefix>
3434
}]

docs/rules/jsx-indent-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ It takes an option as the second parameter which can be `"tab"` for tab-based in
3333

3434
```js
3535
...
36-
"jsx-indent-props": [<enabled>, 'tab'|<number>]
36+
"react/jsx-indent-props": [<enabled>, 'tab'|<number>]
3737
...
3838
```
3939

docs/rules/jsx-max-props-per-line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The following patterns are not considered warnings:
3535

3636
```js
3737
...
38-
"jsx-max-props-per-line": [<enabled>, { "maximum": <number>, "when": <string> }]
38+
"react/jsx-max-props-per-line": [<enabled>, { "maximum": <number>, "when": <string> }]
3939
...
4040
```
4141

docs/rules/jsx-no-bind.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The following patterns are not considered warnings:
2121
## Rule Options
2222

2323
```js
24-
"jsx-no-bind": [<enabled>, {
24+
"react/jsx-no-bind": [<enabled>, {
2525
"ignoreRefs": <boolean> || false,
2626
"allowArrowFunctions": <boolean> || false,
2727
"allowBind": <boolean> || false

docs/rules/jsx-no-duplicate-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The following patterns are not considered warnings:
2020

2121
```js
2222
...
23-
"jsx-no-duplicate-props": [<enabled>, { "ignoreCase": <boolean> }]
23+
"react/jsx-no-duplicate-props": [<enabled>, { "ignoreCase": <boolean> }]
2424
...
2525
```
2626

docs/rules/jsx-pascal-case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The following patterns are not considered warnings:
4040

4141
```js
4242
...
43-
"jsx-pascal-case": [<enabled>, { allowAllCaps: <allowAllCaps>, ignore: <ignore> }]
43+
"react/jsx-pascal-case": [<enabled>, { allowAllCaps: <allowAllCaps>, ignore: <ignore> }]
4444
...
4545
```
4646

docs/rules/jsx-sort-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following patterns are considered okay and do not cause warnings:
2323

2424
```js
2525
...
26-
"jsx-sort-props": [<enabled>, {
26+
"react/jsx-sort-props": [<enabled>, {
2727
"callbacksLast": <boolean>,
2828
"shorthandFirst": <boolean>,
2929
"shorthandLast": <boolean>,

docs/rules/no-did-mount-set-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var Hello = React.createClass({
5353

5454
```js
5555
...
56-
"no-did-mount-set-state": [<enabled>, <mode>]
56+
"react/no-did-mount-set-state": [<enabled>, <mode>]
5757
...
5858
```
5959

docs/rules/no-did-update-set-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var Hello = React.createClass({
5151

5252
```js
5353
...
54-
"no-did-update-set-state": [<enabled>, <mode>]
54+
"react/no-did-update-set-state": [<enabled>, <mode>]
5555
...
5656
```
5757

docs/rules/no-multi-comp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var HelloJohn = React.createClass({
3636

3737
```js
3838
...
39-
"no-multi-comp": [<enabled>, { "ignoreStateless": <boolean> }]
39+
"react/no-multi-comp": [<enabled>, { "ignoreStateless": <boolean> }]
4040
...
4141
```
4242

docs/rules/no-render-return-value.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> `ReactDOM.render()` currently returns a reference to the root `ReactComponent` instance. However, using this return value is legacy and should be avoided because future versions of React may render components asynchronously in some cases. If you need a reference to the root `ReactComponent` instance, the preferred solution is to attach a [callback ref](http://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute) to the root element.
44
5-
Source: [React Top-Level API documentation](http://facebook.github.io/react/docs/top-level-api.html#reactdom.render)
5+
Source: [ReactDOM documentation](https://facebook.github.io/react/docs/react-dom.html#render)
66

77
## Rule Details
88

docs/rules/no-string-refs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prevent using string references (no-string-refs)
22

3-
Currently, two ways are supported by React to refer to components. The first one, providing a string identifier is considered legacy in the official documentation. Referring to components by setting a property on the `this` object in the reference callback is preferred.
3+
Currently, two ways are supported by React to refer to components. The first way, providing a string identifier, is now considered legacy in the official documentation. The documentation now prefers a second method -- referring to components by setting a property on the `this` object in the reference callback.
44

55
## Rule Details
66

docs/rules/no-unknown-property.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Hello = <div className="hello">Hello World</div>;
2626

2727
```js
2828
...
29-
"no-unknown-property": [<enabled>, { ignore: <ignore> }]
29+
"react/no-unknown-property": [<enabled>, { ignore: <ignore> }]
3030
...
3131
```
3232

docs/rules/no-unused-prop-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Hello = React.createClass({
2020
propTypes: {
2121
firstname: React.PropTypes.string.isRequired,
2222
middlename: React.PropTypes.string.isRequired, // middlename is never used below
23-
lastname: React.PropTypes.string.isRequired
23+
lastname: React.PropTypes.string.isRequired
2424
},
2525
render: function() {
2626
return <div>Hello {this.props.firstname} {this.props.lastname}</div>;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Prevent usage of setState in componentWillUpdate (no-will-update-set-state)
2+
3+
Updating the state during the componentWillUpdate step can lead to indeterminate component state and is not allowed.
4+
5+
## Rule Details
6+
7+
The following patterns are considered warnings:
8+
9+
```jsx
10+
var Hello = React.createClass({
11+
componentWillUpdate: function() {
12+
this.setState({
13+
name: this.props.name.toUpperCase()
14+
});
15+
},
16+
render: function() {
17+
return <div>Hello {this.state.name}</div>;
18+
}
19+
});
20+
```
21+
22+
The following patterns are not considered warnings:
23+
24+
```jsx
25+
var Hello = React.createClass({
26+
componentWillUpdate: function() {
27+
this.props.prepareHandler();
28+
},
29+
render: function() {
30+
return <div>Hello {this.props.name}</div>;
31+
}
32+
});
33+
```
34+
35+
```jsx
36+
var Hello = React.createClass({
37+
componentWillUpdate: function() {
38+
this.prepareHandler(function callback(newName) {
39+
this.setState({
40+
name: newName
41+
});
42+
});
43+
},
44+
render: function() {
45+
return <div>Hello {this.props.name}</div>;
46+
}
47+
});
48+
```
49+
50+
## Rule Options
51+
52+
```js
53+
...
54+
"react/no-will-update-set-state": [<enabled>, <mode>]
55+
...
56+
```
57+
58+
### `disallow-in-func` mode
59+
60+
By default this rule forbids any call to `this.setState` in `componentWillUpdate` outside of functions. The `disallow-in-func` mode makes this rule more strict by disallowing calls to `this.setState` even within functions.
61+
62+
The following patterns are considered warnings:
63+
64+
```jsx
65+
var Hello = React.createClass({
66+
componentDidUpdate: function() {
67+
this.setState({
68+
name: this.props.name.toUpperCase()
69+
});
70+
},
71+
render: function() {
72+
return <div>Hello {this.state.name}</div>;
73+
}
74+
});
75+
```
76+
77+
```jsx
78+
var Hello = React.createClass({
79+
componentDidUpdate: function() {
80+
this.prepareHandler(function callback(newName) {
81+
this.setState({
82+
name: newName
83+
});
84+
});
85+
},
86+
render: function() {
87+
return <div>Hello {this.state.name}</div>;
88+
}
89+
});
90+
```

docs/rules/prefer-es6-class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ React offers you two way to create traditional components: using the ES5 `React.
66

77
```js
88
...
9-
"prefer-es6-class": [<enabled>, <mode>]
9+
"react/prefer-es6-class": [<enabled>, <mode>]
1010
...
1111
```
1212

docs/rules/prefer-stateless-function.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This rule will check your class based React components for
1010
* instance property other than `this.props` and `this.context`
1111
* extension of `React.PureComponent` (if the `ignorePureComponents` flag is true)
1212
* presence of `ref` attribute in JSX
13+
* the use of decorators
1314
* `render` method that return anything but JSX: `undefined`, `null`, etc. (only in React <15.0.0, see [shared settings](https://github.com/yannickcr/eslint-plugin-react/blob/master/README.md#configuration) for React version configuration)
1415

1516
If none of these elements are found, the rule will warn you to write this component as a pure function.
@@ -54,7 +55,7 @@ class Foo extends React.Component {
5455

5556
```js
5657
...
57-
"prefer-stateless-function": [<enabled>, { "ignorePureComponents": <ignorePureComponents> }]
58+
"react/prefer-stateless-function": [<enabled>, { "ignorePureComponents": <ignorePureComponents> }]
5859
...
5960
```
6061

docs/rules/require-optimization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ React.createClass({
5252

5353
```js
5454
...
55-
"require-optimization": [<enabled>, { allowDecorators: [<allowDecorator>] }]
55+
"react/require-optimization": [<enabled>, { allowDecorators: [<allowDecorator>] }]
5656
...
5757
```
5858

@@ -76,6 +76,6 @@ class Hello extends React.Component {}
7676

7777
```js
7878
...
79-
"require-optimization": [2, {allowDecorators: ['customDecorators']}]
79+
"react/require-optimization": [2, {allowDecorators: ['customDecorators']}]
8080
...
8181
```

docs/rules/self-closing-comp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The rule can take one argument to select types of tags, which should be self-clo
3232

3333
```js
3434
...
35-
"self-closing-comp": ["error", {
35+
"react/self-closing-comp": ["error", {
3636
"component": true,
3737
"html": true
3838
}]

docs/rules/sort-prop-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Component extends React.Component {
7676

7777
```js
7878
...
79-
"sort-prop-types": [<enabled>, {
79+
"react/sort-prop-types": [<enabled>, {
8080
"callbacksLast": <boolean>,
8181
"ignoreCase": <boolean>,
8282
"requiredFirst": <boolean>,

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var allRules = {
2020
'no-did-update-set-state': require('./lib/rules/no-did-update-set-state'),
2121
'no-render-return-value': require('./lib/rules/no-render-return-value'),
2222
'no-unescaped-entities': require('./lib/rules/no-unescaped-entities'),
23+
'no-will-update-set-state': require('./lib/rules/no-will-update-set-state'),
2324
'react-in-jsx-scope': require('./lib/rules/react-in-jsx-scope'),
2425
'jsx-uses-vars': require('./lib/rules/jsx-uses-vars'),
2526
'jsx-handler-names': require('./lib/rules/jsx-handler-names'),

0 commit comments

Comments
 (0)