Skip to content

Commit acc35a1

Browse files
committed
Merge branch 'master' into lukyth/state-in-constructor
2 parents b0e4c84 + b48b479 commit acc35a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3027
-415
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ logs
1515
reports
1616
build
1717
node_modules
18+
!tests/**/node_modules
1819
npm-debug.log
1920
sftp-config.json
2021

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
sudo: false
22
language: node_js
33
node_js:
4+
- '11'
45
- '10'
5-
- '9'
66
- '8'
7-
- '7'
87
- '6'
9-
- '5'
108
- '4'
119
before_install:
1210
- 'nvm install-latest-npm'
@@ -30,11 +28,7 @@ matrix:
3028
- node_js: 'lts/*'
3129
env: PRETEST=true
3230
exclude:
33-
- node_js: '5'
34-
env: ESLINT=5
3531
- node_js: '4'
3632
env: ESLINT=5
3733
allow_failures:
38-
- node_js: '9'
39-
- node_js: '7'
40-
- node_js: '5'
34+
- node_js: '11'

CHANGELOG.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,127 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

6+
## [7.12.2] - 2019-01-02
7+
8+
### Fixed
9+
* [`prop-types`][]: avoid crash on used prevProps ([#2095][], @ljharb)
10+
* Version warning: Link does not end with '.' ([#2103][], @yoyo837))
11+
* [`forbid-prop-types`][]: fix crash with propWrapper check on MemberExpressions ([#2104][], @ljharb)
12+
13+
[#2104]: https://github.com/yannickcr/eslint-plugin-react/issues/2104
14+
[#2103]: https://github.com/yannickcr/eslint-plugin-react/pull/2103
15+
[#2095]: https://github.com/yannickcr/eslint-plugin-react/issues/2095
16+
17+
## [7.12.1] - 2019-01-01
18+
19+
### Fixed
20+
* [`no-unused-state`][]: Fix crash with class fields ([#2098][], @jomasti)
21+
* [`prop-types`][]: Fix false positives inside lifecycle methods ([#2099][], @jomasti)
22+
* [`jsx-max-depth`][]: avoid a crash ([#2102][], @ljharb)
23+
* [`jsx-wrap-multilines`][]: avoid crash when no trailing newline ([#2100][], @ljharb)
24+
25+
### Changed
26+
* Fix CHANGELOG.md ([#2097][], @alexzherdev)
27+
28+
[#2102]: https://github.com/yannickcr/eslint-plugin-react/issues/2102
29+
[#2100]: https://github.com/yannickcr/eslint-plugin-react/issues/2100
30+
[#2099]: https://github.com/yannickcr/eslint-plugin-react/pull/2099
31+
[#2098]: https://github.com/yannickcr/eslint-plugin-react/pull/2098
32+
[#2097]: https://github.com/yannickcr/eslint-plugin-react/pull/2097
33+
34+
## [7.12.0] - 2018-12-27
35+
36+
### Added
37+
* [`no-typos`]: Support createClass ([#1828][], @alexzherdev)
38+
* Support detecting React.forwardRef/React.memo ([#2089][], @jomasti)
39+
* [`jsx-indent`][]: add `checkAttributes` option for JSX attribute indentation ([#2086][], @jomasti)
40+
* Change allowed `propWrapperFunctions` setting values ([#2065][], @jomasti)
41+
* add [`jsx-fragments`][] rule to enforce fragment syntax ([#1994][], @alexzherdev)
42+
* Support "detect" option for React version setting ([#1978][], @alexzherdev)
43+
* Support shorthand fragment syntax in many rules ([#1956][], @alexzherdev)
44+
* [`jsx-no-literals`][]: print node value in warning message ([#2008][], @jlgonzalezdev)
45+
46+
### Fixed
47+
* [`jsx-max-depth`][]: Fix depth of JSX siblings in a JSXEpressionContainer ([#1824][], @alexzherdev)
48+
* [`no-array-index-key`][]: fix in React.Children methods ([#2085][], @himynameisdave)
49+
* [`no-unused-state`][]: handle functional setState ([#2084][], @jomasti)
50+
* version errors should log to stderr, not stdout ([#2082][], @ljharb)
51+
* [`no-deprecated`][]: Disable legacy lifecycle methods linting for now ([#2069][], @sergei-startsev)
52+
* ensure that react and flow versions can be numbers ([#2056][], @ljharb)
53+
* [`forbid-foreign-prop-types`][]: ensure `allowInPropTypes` option applies to class fields ([#2040][], @Sheile)
54+
* [`jsx-wrap-multilines`][]: catch single missing newlines ([#1984][], @MrHen)
55+
* [`jsx-first-prop-new-line`][]: Fix for parsers (like TypeScript) ([#2026][], @HauptmannEck)
56+
* [`sort-comp`][]: Fix fixer in case of more than 10 props ([#2012][], @tihonove)
57+
* [`no-unused-state`][] Don't depend on state parameter name ([#1829][], @alexzherdev)
58+
* [`no-this-in-sfc`][] fix for class properties ([#1995][], @sergei-startsev)
59+
* [`no-this-in-sfc`][] fix rule behavior for arrow functions inside a class field ([#1989][], @sergei-startsev)
60+
* [`destructuring-assignment`][]: handle nested props usage ([#1983][], @alexzherdev)
61+
* [`sort-prop-types`][]: fix string property order ([#1977][], @metreniuk)
62+
* [`jsx-no-target-blank`][]: don’t crash when there’s no value ([#1949][], @ljharb)
63+
* [`prop-types`][], [`no-unused-prop-types`][]: better handle object spread ([#1939][], @alexzherdev)
64+
65+
### Changed
66+
* [`jsx-fragments`][]: improve message text ([#2032][], @alexzherdev)
67+
* [`no-unsafe`][]: handle all unsafe life-cycle methods ([#2075][], @sergei-startsev)
68+
* [`require-default-props`][]: Change error message naming from singular defaultProp to plural defaultProps ([#2064][], @jseminck)
69+
* [Refactor] Extract used `propTypes` detection ([#1946][], @alexzherdev)
70+
* [Refactor] Extract `defaultProps` detection ([#1942][], @alexzherdev)
71+
* [Refactor] Extract required `propTypes` detection ([#2001][], @alexzherdev)
72+
* [Docs] [`no-did-mount-set-state`][], [`no-did-update-set-state`][], [`no-will-update-set-state`][]: fix docs URLs ([#2090][], @JBallin)
73+
* [Docs] Remove statement on GC in jsx-no-bind ([#2067][], @rickhanlonii)
74+
* [Docs] [`jsx-sort-props`][]: Fix small mistake ([#2044][], @dimitarnestorov)
75+
* [Docs] [`no-unescaped-entities`][]: add more escape examples ([#2015][], @stevemao)
76+
* [Docs] [`display-name`][]: mention default `ignoreTranspilerName` value ([#2002][], @OliverJAsh)
77+
* [Docs] [`jsx-no-target-blank`][]: Add full example ([#1988][], @atomcorp)
78+
* [Docs] Update [`jsx-no-target-blank`][].md ([#1953][], @brunocoelho)
79+
* [Changelog] fix "Ignore class properties" contributor ([#1941][], @alexzherdev)
80+
* [Tests] Remove redundant `require('babel-eslint')` from tests ([#2004][], @sergei-startsev)
81+
* [Tests] [`prop-types`][]: Add tests for prop-types destructuring ([#2029][], @sstern6)
82+
* [Tests] [`display-name`][]: add false positive component detection for destructured createElement ([#1098][], @arian)
83+
84+
[#2090]: https://github.com/yannickcr/eslint-plugin-react/pull/2090
85+
[#2089]: https://github.com/yannickcr/eslint-plugin-react/pull/2089
86+
[#2086]: https://github.com/yannickcr/eslint-plugin-react/pull/2086
87+
[#2085]: https://github.com/yannickcr/eslint-plugin-react/pull/2085
88+
[#2084]: https://github.com/yannickcr/eslint-plugin-react/pull/2084
89+
[#2082]: https://github.com/yannickcr/eslint-plugin-react/issues/2082
90+
[#2075]: https://github.com/yannickcr/eslint-plugin-react/pull/2075
91+
[#2069]: https://github.com/yannickcr/eslint-plugin-react/pull/2069
92+
[#2067]: https://github.com/yannickcr/eslint-plugin-react/pull/2067
93+
[#2065]: https://github.com/yannickcr/eslint-plugin-react/pull/2065
94+
[#2064]: https://github.com/yannickcr/eslint-plugin-react/pull/2064
95+
[#2056]: https://github.com/yannickcr/eslint-plugin-react/issues/2056
96+
[#2044]: https://github.com/yannickcr/eslint-plugin-react/pull/2044
97+
[#2040]: https://github.com/yannickcr/eslint-plugin-react/pull/2040
98+
[#2032]: https://github.com/yannickcr/eslint-plugin-react/pull/2032
99+
[#2029]: https://github.com/yannickcr/eslint-plugin-react/pull/2029
100+
[#2026]: https://github.com/yannickcr/eslint-plugin-react/pull/2026
101+
[#2015]: https://github.com/yannickcr/eslint-plugin-react/pull/2015
102+
[#2012]: https://github.com/yannickcr/eslint-plugin-react/pull/2012
103+
[#2008]: https://github.com/yannickcr/eslint-plugin-react/pull/2008
104+
[#2004]: https://github.com/yannickcr/eslint-plugin-react/pull/2004
105+
[#2002]: https://github.com/yannickcr/eslint-plugin-react/pull/2002
106+
[#2001]: https://github.com/yannickcr/eslint-plugin-react/pull/2001
107+
[#1995]: https://github.com/yannickcr/eslint-plugin-react/pull/1995
108+
[#1994]: https://github.com/yannickcr/eslint-plugin-react/pull/1994
109+
[#1989]: https://github.com/yannickcr/eslint-plugin-react/pull/1989
110+
[#1988]: https://github.com/yannickcr/eslint-plugin-react/pull/1988
111+
[#1984]: https://github.com/yannickcr/eslint-plugin-react/pull/1984
112+
[#1983]: https://github.com/yannickcr/eslint-plugin-react/pull/1983
113+
[#1978]: https://github.com/yannickcr/eslint-plugin-react/pull/1978
114+
[#1977]: https://github.com/yannickcr/eslint-plugin-react/pull/1977
115+
[#1956]: https://github.com/yannickcr/eslint-plugin-react/pull/1956
116+
[#1953]: https://github.com/yannickcr/eslint-plugin-react/pull/1953
117+
[#1949]: https://github.com/yannickcr/eslint-plugin-react/issues/1949
118+
[#1946]: https://github.com/yannickcr/eslint-plugin-react/pull/1946
119+
[#1942]: https://github.com/yannickcr/eslint-plugin-react/pull/1942
120+
[#1941]: https://github.com/yannickcr/eslint-plugin-react/pull/1941
121+
[#1939]: https://github.com/yannickcr/eslint-plugin-react/pull/1939
122+
[#1829]: https://github.com/yannickcr/eslint-plugin-react/pull/1829
123+
[#1828]: https://github.com/yannickcr/eslint-plugin-react/pull/1828
124+
[#1824]: https://github.com/yannickcr/eslint-plugin-react/pull/1824
125+
[#1098]: https://github.com/yannickcr/eslint-plugin-react/pull/1098
126+
6127
## [7.11.1] - 2018-08-14
7128
### Fixed
8129
* stop crashing when assigning to propTypes ([#1932][], @alexzherdev)
@@ -2331,3 +2452,4 @@ If you're still not using React 15 you can keep the old behavior by setting the
23312452
[`jsx-max-depth`]: docs/rules/jsx-max-depth.md
23322453
[`jsx-props-no-multi-spaces`]: docs/rules/jsx-props-no-multi-spaces.md
23332454
[`no-unsafe`]: docs/rules/no-unsafe.md
2455+
[`jsx-fragments`]: docs/rules/jsx-fragments.md

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ You should also specify settings that will be shared across all the plugin rules
4242
"version": "15.0", // React version, default to the latest React stable release
4343
"flowVersion": "0.53" // Flow version
4444
},
45-
"propWrapperFunctions": [ "forbidExtraProps" ] // The names of any functions used to wrap the
46-
// propTypes object, e.g. `forbidExtraProps`.
47-
// If this isn't set, any propTypes wrapped in
48-
// a function will be skipped.
45+
"propWrapperFunctions": [
46+
// The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
47+
"forbidExtraProps",
48+
{"property": "freeze", "object": "Object"}
49+
{"property": "myFavoriteWrapper"}
50+
]
4951
}
5052
}
5153
```
@@ -117,7 +119,7 @@ Enable the rules that you would like to use.
117119
* [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md): Prevent using `this` in stateless functional components
118120
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
119121
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
120-
* [react/no-unsafe](docs/rules/no-unsafe.md): Prevent usage of `UNSAFE_` methods
122+
* [react/no-unsafe](docs/rules/no-unsafe.md): Prevent usage of unsafe lifecycle methods
121123
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
122124
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definitions of unused state properties
123125
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
@@ -158,6 +160,7 @@ Enable the rules that you would like to use.
158160
* [react/jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX
159161
* [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md): Limit to one expression per line in JSX
160162
* [react/jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md): Enforce curly braces or disallow unnecessary curly braces in JSX
163+
* [react/jsx-fragments](docs/rules/jsx-fragments.md): Enforce shorthand or standard form for React fragments
161164
* [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md): Enforce PascalCase for user-defined JSX components
162165
* [react/jsx-props-no-multi-spaces](docs/rules/jsx-props-no-multi-spaces.md): Disallow multiple spaces between inline JSX props (fixable)
163166
* [react/jsx-sort-default-props](docs/rules/jsx-sort-default-props.md): Enforce default props alphabetical sorting

docs/rules/jsx-fragments.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Enforce shorthand or standard form for React fragments (react/jsx-fragments)
2+
3+
In JSX, a React fragment is created either with `<React.Fragment>...</React.Fragment>`, or, using the shorthand syntax, `<>...</>`. This rule allows you to enforce one way or the other.
4+
5+
Support for fragments was added in React v16.2, so the rule will warn on either of these forms if an older React version is specified in [shared settings][shared_settings].
6+
7+
## Rule Options
8+
9+
```js
10+
...
11+
"react/jsx-fragments": [<enabled>, <mode>]
12+
...
13+
```
14+
15+
### `syntax` mode
16+
17+
This is the default mode. It will enforce the shorthand syntax for React fragments, with one exception. [Keys or attributes are not supported by the shorthand syntax][short_syntax], so the rule will not warn on standard-form fragments that use those.
18+
19+
The following pattern is considered a warning:
20+
21+
```jsx
22+
<React.Fragment><Foo /></React.Fragment>
23+
```
24+
25+
The following patterns are **not** considered warnings:
26+
27+
```jsx
28+
<><Foo /></>
29+
```
30+
31+
```jsx
32+
<React.Fragment key="key"><Foo /></React.Fragment>
33+
```
34+
35+
### `element` mode
36+
37+
This mode enforces the standard form for React fragments.
38+
39+
The following pattern is considered a warning:
40+
41+
```jsx
42+
<><Foo /></>
43+
```
44+
45+
The following patterns are **not** considered warnings:
46+
47+
```jsx
48+
<React.Fragment><Foo /></React.Fragment>
49+
```
50+
51+
```jsx
52+
<React.Fragment key="key"><Foo /></React.Fragment>
53+
```
54+
55+
[fragments]: https://reactjs.org/docs/fragments.html
56+
[shared_settings]: /README.md#configuration
57+
[short_syntax]: https://reactjs.org/docs/fragments.html#short-syntax

docs/rules/jsx-indent.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ The following patterns are considered warnings:
3131
## Rule Options
3232

3333
It takes an option as the second parameter which can be `"tab"` for tab-based indentation or a positive number for space indentations.
34+
To enable checking the indentation of attributes, use the third parameter to turn on the `checkAttributes` option (default is false).
3435

3536
```js
3637
...
37-
"react/jsx-indent": [<enabled>, 'tab'|<number>]
38+
"react/jsx-indent": [<enabled>, 'tab'|<number>, {checkAttributes: <boolean>}]
3839
...
3940
```
4041

@@ -52,6 +53,14 @@ The following patterns are considered warnings:
5253
<App>
5354
<Hello />
5455
</App>
56+
57+
// [2, 2, {checkAttributes: true}]
58+
<App render={
59+
<Hello render={
60+
(bar) => <div>hi</div>
61+
}
62+
/>
63+
</App>
5564
```
5665
5766
The following patterns are **not** warnings:
@@ -75,6 +84,14 @@ The following patterns are **not** warnings:
7584
<App>
7685
<Hello />
7786
</App>
87+
88+
// [2, 2, {checkAttributes: false}]
89+
<App render={
90+
<Hello render={
91+
(bar) => <div>hi</div>
92+
}
93+
/>
94+
</App>
7895
```
7996
8097
## When not to use

docs/rules/jsx-no-bind.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# No `.bind()` or Arrow Functions in JSX Props (react/jsx-no-bind)
22

3-
A `bind` call or [arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) in a JSX prop will create a brand new function on every single render. This is bad for performance, as it will result in the garbage collector being invoked way more than is necessary. It may also cause unnecessary re-renders if a brand new function is passed as a prop to a component that uses reference equality check on the prop to determine if it should update.
3+
A `bind` call or [arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) in a JSX prop will create a brand new function on every single render. This is bad for performance, as it may cause unnecessary re-renders if a brand new function is passed as a prop to a component that uses reference equality check on the prop to determine if it should update.
44

55
## Rule Details
66

docs/rules/jsx-sort-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ When `reservedFirst` is defined, React reserved props (`children`, `dangerouslyS
9292

9393
If given as an array, the array's values will override the default list of reserved props. **Note**: the values in the array may only be a **subset** of React reserved props.
9494

95-
With `reservedFirst: [2, ["key"]]`, the following will **not** warn:
95+
With `reservedFirst: ["key"]`, the following will **not** warn:
9696

9797
```jsx
9898
<Hello key={'uuid'} name="John" ref="ref" />

docs/rules/no-array-index-key.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ things.reduce((collection, thing, index) => (
5050
things.reduceRight((collection, thing, index) => (
5151
collection.concat(<Hello key={index} />)
5252
), []);
53+
54+
React.Children.map(this.props.children, (child, index) => (
55+
React.cloneElement(child, { key: index })
56+
))
57+
58+
Children.forEach(this.props.children, (child, index) => (
59+
React.cloneElement(child, { key: index })
60+
))
5361
```
5462

5563
The following patterns are **not** considered warnings:

docs/rules/no-deprecated.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@ const propTypes = {
2727
React.DOM.div();
2828

2929
import React, { PropTypes } from 'react';
30-
31-
class Foo extends React.Component {
32-
componentWillMount() { }
33-
componentWillReceiveProps() { }
34-
componentWillUpdate() { }
35-
// ...
36-
}
37-
38-
class Foo extends React.PureComponent {
39-
componentWillMount() { }
40-
componentWillReceiveProps() { }
41-
componentWillUpdate() { }
42-
// ...
43-
}
44-
45-
var Foo = createReactClass({
46-
componentWillMount: function() {},
47-
componentWillReceiveProps: function() {},
48-
componentWillUpdate: function() {},
49-
// ...
50-
})
5130
```
5231

5332
The following patterns are **not** considered warnings:
@@ -59,10 +38,4 @@ ReactDOM.render(<MyComponent />, root);
5938
ReactDOM.findDOMNode(this.refs.foo);
6039

6140
import { PropTypes } from 'prop-types';
62-
63-
class Foo {
64-
componentWillMount() { }
65-
componentWillReceiveProps() { }
66-
componentWillUpdate() { }
67-
}
6841
```

0 commit comments

Comments
 (0)