Skip to content

Commit

Permalink
Merge branch 'master' into lukyth/state-in-constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lukyth committed Jan 3, 2019
2 parents b0e4c84 + b48b479 commit acc35a1
Show file tree
Hide file tree
Showing 68 changed files with 3,027 additions and 415 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ logs
reports
build
node_modules
!tests/**/node_modules
npm-debug.log
sftp-config.json

Expand Down
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
sudo: false
language: node_js
node_js:
- '11'
- '10'
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
before_install:
- 'nvm install-latest-npm'
Expand All @@ -30,11 +28,7 @@ matrix:
- node_js: 'lts/*'
env: PRETEST=true
exclude:
- node_js: '5'
env: ESLINT=5
- node_js: '4'
env: ESLINT=5
allow_failures:
- node_js: '9'
- node_js: '7'
- node_js: '5'
- node_js: '11'
122 changes: 122 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,127 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [7.12.2] - 2019-01-02

### Fixed
* [`prop-types`][]: avoid crash on used prevProps ([#2095][], @ljharb)
* Version warning: Link does not end with '.' ([#2103][], @yoyo837))
* [`forbid-prop-types`][]: fix crash with propWrapper check on MemberExpressions ([#2104][], @ljharb)

[#2104]: https://github.com/yannickcr/eslint-plugin-react/issues/2104
[#2103]: https://github.com/yannickcr/eslint-plugin-react/pull/2103
[#2095]: https://github.com/yannickcr/eslint-plugin-react/issues/2095

## [7.12.1] - 2019-01-01

### Fixed
* [`no-unused-state`][]: Fix crash with class fields ([#2098][], @jomasti)
* [`prop-types`][]: Fix false positives inside lifecycle methods ([#2099][], @jomasti)
* [`jsx-max-depth`][]: avoid a crash ([#2102][], @ljharb)
* [`jsx-wrap-multilines`][]: avoid crash when no trailing newline ([#2100][], @ljharb)

### Changed
* Fix CHANGELOG.md ([#2097][], @alexzherdev)

[#2102]: https://github.com/yannickcr/eslint-plugin-react/issues/2102
[#2100]: https://github.com/yannickcr/eslint-plugin-react/issues/2100
[#2099]: https://github.com/yannickcr/eslint-plugin-react/pull/2099
[#2098]: https://github.com/yannickcr/eslint-plugin-react/pull/2098
[#2097]: https://github.com/yannickcr/eslint-plugin-react/pull/2097

## [7.12.0] - 2018-12-27

### Added
* [`no-typos`]: Support createClass ([#1828][], @alexzherdev)
* Support detecting React.forwardRef/React.memo ([#2089][], @jomasti)
* [`jsx-indent`][]: add `checkAttributes` option for JSX attribute indentation ([#2086][], @jomasti)
* Change allowed `propWrapperFunctions` setting values ([#2065][], @jomasti)
* add [`jsx-fragments`][] rule to enforce fragment syntax ([#1994][], @alexzherdev)
* Support "detect" option for React version setting ([#1978][], @alexzherdev)
* Support shorthand fragment syntax in many rules ([#1956][], @alexzherdev)
* [`jsx-no-literals`][]: print node value in warning message ([#2008][], @jlgonzalezdev)

### Fixed
* [`jsx-max-depth`][]: Fix depth of JSX siblings in a JSXEpressionContainer ([#1824][], @alexzherdev)
* [`no-array-index-key`][]: fix in React.Children methods ([#2085][], @himynameisdave)
* [`no-unused-state`][]: handle functional setState ([#2084][], @jomasti)
* version errors should log to stderr, not stdout ([#2082][], @ljharb)
* [`no-deprecated`][]: Disable legacy lifecycle methods linting for now ([#2069][], @sergei-startsev)
* ensure that react and flow versions can be numbers ([#2056][], @ljharb)
* [`forbid-foreign-prop-types`][]: ensure `allowInPropTypes` option applies to class fields ([#2040][], @Sheile)
* [`jsx-wrap-multilines`][]: catch single missing newlines ([#1984][], @MrHen)
* [`jsx-first-prop-new-line`][]: Fix for parsers (like TypeScript) ([#2026][], @HauptmannEck)
* [`sort-comp`][]: Fix fixer in case of more than 10 props ([#2012][], @tihonove)
* [`no-unused-state`][] Don't depend on state parameter name ([#1829][], @alexzherdev)
* [`no-this-in-sfc`][] fix for class properties ([#1995][], @sergei-startsev)
* [`no-this-in-sfc`][] fix rule behavior for arrow functions inside a class field ([#1989][], @sergei-startsev)
* [`destructuring-assignment`][]: handle nested props usage ([#1983][], @alexzherdev)
* [`sort-prop-types`][]: fix string property order ([#1977][], @metreniuk)
* [`jsx-no-target-blank`][]: don’t crash when there’s no value ([#1949][], @ljharb)
* [`prop-types`][], [`no-unused-prop-types`][]: better handle object spread ([#1939][], @alexzherdev)

### Changed
* [`jsx-fragments`][]: improve message text ([#2032][], @alexzherdev)
* [`no-unsafe`][]: handle all unsafe life-cycle methods ([#2075][], @sergei-startsev)
* [`require-default-props`][]: Change error message naming from singular defaultProp to plural defaultProps ([#2064][], @jseminck)
* [Refactor] Extract used `propTypes` detection ([#1946][], @alexzherdev)
* [Refactor] Extract `defaultProps` detection ([#1942][], @alexzherdev)
* [Refactor] Extract required `propTypes` detection ([#2001][], @alexzherdev)
* [Docs] [`no-did-mount-set-state`][], [`no-did-update-set-state`][], [`no-will-update-set-state`][]: fix docs URLs ([#2090][], @JBallin)
* [Docs] Remove statement on GC in jsx-no-bind ([#2067][], @rickhanlonii)
* [Docs] [`jsx-sort-props`][]: Fix small mistake ([#2044][], @dimitarnestorov)
* [Docs] [`no-unescaped-entities`][]: add more escape examples ([#2015][], @stevemao)
* [Docs] [`display-name`][]: mention default `ignoreTranspilerName` value ([#2002][], @OliverJAsh)
* [Docs] [`jsx-no-target-blank`][]: Add full example ([#1988][], @atomcorp)
* [Docs] Update [`jsx-no-target-blank`][].md ([#1953][], @brunocoelho)
* [Changelog] fix "Ignore class properties" contributor ([#1941][], @alexzherdev)
* [Tests] Remove redundant `require('babel-eslint')` from tests ([#2004][], @sergei-startsev)
* [Tests] [`prop-types`][]: Add tests for prop-types destructuring ([#2029][], @sstern6)
* [Tests] [`display-name`][]: add false positive component detection for destructured createElement ([#1098][], @arian)

[#2090]: https://github.com/yannickcr/eslint-plugin-react/pull/2090
[#2089]: https://github.com/yannickcr/eslint-plugin-react/pull/2089
[#2086]: https://github.com/yannickcr/eslint-plugin-react/pull/2086
[#2085]: https://github.com/yannickcr/eslint-plugin-react/pull/2085
[#2084]: https://github.com/yannickcr/eslint-plugin-react/pull/2084
[#2082]: https://github.com/yannickcr/eslint-plugin-react/issues/2082
[#2075]: https://github.com/yannickcr/eslint-plugin-react/pull/2075
[#2069]: https://github.com/yannickcr/eslint-plugin-react/pull/2069
[#2067]: https://github.com/yannickcr/eslint-plugin-react/pull/2067
[#2065]: https://github.com/yannickcr/eslint-plugin-react/pull/2065
[#2064]: https://github.com/yannickcr/eslint-plugin-react/pull/2064
[#2056]: https://github.com/yannickcr/eslint-plugin-react/issues/2056
[#2044]: https://github.com/yannickcr/eslint-plugin-react/pull/2044
[#2040]: https://github.com/yannickcr/eslint-plugin-react/pull/2040
[#2032]: https://github.com/yannickcr/eslint-plugin-react/pull/2032
[#2029]: https://github.com/yannickcr/eslint-plugin-react/pull/2029
[#2026]: https://github.com/yannickcr/eslint-plugin-react/pull/2026
[#2015]: https://github.com/yannickcr/eslint-plugin-react/pull/2015
[#2012]: https://github.com/yannickcr/eslint-plugin-react/pull/2012
[#2008]: https://github.com/yannickcr/eslint-plugin-react/pull/2008
[#2004]: https://github.com/yannickcr/eslint-plugin-react/pull/2004
[#2002]: https://github.com/yannickcr/eslint-plugin-react/pull/2002
[#2001]: https://github.com/yannickcr/eslint-plugin-react/pull/2001
[#1995]: https://github.com/yannickcr/eslint-plugin-react/pull/1995
[#1994]: https://github.com/yannickcr/eslint-plugin-react/pull/1994
[#1989]: https://github.com/yannickcr/eslint-plugin-react/pull/1989
[#1988]: https://github.com/yannickcr/eslint-plugin-react/pull/1988
[#1984]: https://github.com/yannickcr/eslint-plugin-react/pull/1984
[#1983]: https://github.com/yannickcr/eslint-plugin-react/pull/1983
[#1978]: https://github.com/yannickcr/eslint-plugin-react/pull/1978
[#1977]: https://github.com/yannickcr/eslint-plugin-react/pull/1977
[#1956]: https://github.com/yannickcr/eslint-plugin-react/pull/1956
[#1953]: https://github.com/yannickcr/eslint-plugin-react/pull/1953
[#1949]: https://github.com/yannickcr/eslint-plugin-react/issues/1949
[#1946]: https://github.com/yannickcr/eslint-plugin-react/pull/1946
[#1942]: https://github.com/yannickcr/eslint-plugin-react/pull/1942
[#1941]: https://github.com/yannickcr/eslint-plugin-react/pull/1941
[#1939]: https://github.com/yannickcr/eslint-plugin-react/pull/1939
[#1829]: https://github.com/yannickcr/eslint-plugin-react/pull/1829
[#1828]: https://github.com/yannickcr/eslint-plugin-react/pull/1828
[#1824]: https://github.com/yannickcr/eslint-plugin-react/pull/1824
[#1098]: https://github.com/yannickcr/eslint-plugin-react/pull/1098

## [7.11.1] - 2018-08-14
### Fixed
* stop crashing when assigning to propTypes ([#1932][], @alexzherdev)
Expand Down Expand Up @@ -2331,3 +2452,4 @@ If you're still not using React 15 you can keep the old behavior by setting the
[`jsx-max-depth`]: docs/rules/jsx-max-depth.md
[`jsx-props-no-multi-spaces`]: docs/rules/jsx-props-no-multi-spaces.md
[`no-unsafe`]: docs/rules/no-unsafe.md
[`jsx-fragments`]: docs/rules/jsx-fragments.md
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ You should also specify settings that will be shared across all the plugin rules
"version": "15.0", // React version, default to the latest React stable release
"flowVersion": "0.53" // Flow version
},
"propWrapperFunctions": [ "forbidExtraProps" ] // The names of any functions used to wrap the
// propTypes object, e.g. `forbidExtraProps`.
// If this isn't set, any propTypes wrapped in
// a function will be skipped.
"propWrapperFunctions": [
// 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.
"forbidExtraProps",
{"property": "freeze", "object": "Object"}
{"property": "myFavoriteWrapper"}
]
}
}
```
Expand Down Expand Up @@ -117,7 +119,7 @@ Enable the rules that you would like to use.
* [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md): Prevent using `this` in stateless functional components
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
* [react/no-unsafe](docs/rules/no-unsafe.md): Prevent usage of `UNSAFE_` methods
* [react/no-unsafe](docs/rules/no-unsafe.md): Prevent usage of unsafe lifecycle methods
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definitions of unused state properties
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
Expand Down Expand Up @@ -158,6 +160,7 @@ Enable the rules that you would like to use.
* [react/jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX
* [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md): Limit to one expression per line in JSX
* [react/jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md): Enforce curly braces or disallow unnecessary curly braces in JSX
* [react/jsx-fragments](docs/rules/jsx-fragments.md): Enforce shorthand or standard form for React fragments
* [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md): Enforce PascalCase for user-defined JSX components
* [react/jsx-props-no-multi-spaces](docs/rules/jsx-props-no-multi-spaces.md): Disallow multiple spaces between inline JSX props (fixable)
* [react/jsx-sort-default-props](docs/rules/jsx-sort-default-props.md): Enforce default props alphabetical sorting
Expand Down
57 changes: 57 additions & 0 deletions docs/rules/jsx-fragments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Enforce shorthand or standard form for React fragments (react/jsx-fragments)

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.

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].

## Rule Options

```js
...
"react/jsx-fragments": [<enabled>, <mode>]
...
```

### `syntax` mode

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.

The following pattern is considered a warning:

```jsx
<React.Fragment><Foo /></React.Fragment>
```

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

```jsx
<><Foo /></>
```

```jsx
<React.Fragment key="key"><Foo /></React.Fragment>
```

### `element` mode

This mode enforces the standard form for React fragments.

The following pattern is considered a warning:

```jsx
<><Foo /></>
```

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

```jsx
<React.Fragment><Foo /></React.Fragment>
```

```jsx
<React.Fragment key="key"><Foo /></React.Fragment>
```

[fragments]: https://reactjs.org/docs/fragments.html
[shared_settings]: /README.md#configuration
[short_syntax]: https://reactjs.org/docs/fragments.html#short-syntax
19 changes: 18 additions & 1 deletion docs/rules/jsx-indent.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ The following patterns are considered warnings:
## Rule Options

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

```js
...
"react/jsx-indent": [<enabled>, 'tab'|<number>]
"react/jsx-indent": [<enabled>, 'tab'|<number>, {checkAttributes: <boolean>}]
...
```

Expand All @@ -52,6 +53,14 @@ The following patterns are considered warnings:
<App>
<Hello />
</App>

// [2, 2, {checkAttributes: true}]
<App render={
<Hello render={
(bar) => <div>hi</div>
}
/>
</App>
```
The following patterns are **not** warnings:
Expand All @@ -75,6 +84,14 @@ The following patterns are **not** warnings:
<App>
<Hello />
</App>

// [2, 2, {checkAttributes: false}]
<App render={
<Hello render={
(bar) => <div>hi</div>
}
/>
</App>
```
## When not to use
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/jsx-no-bind.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# No `.bind()` or Arrow Functions in JSX Props (react/jsx-no-bind)

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.
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.

## Rule Details

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/jsx-sort-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ When `reservedFirst` is defined, React reserved props (`children`, `dangerouslyS

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.

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

```jsx
<Hello key={'uuid'} name="John" ref="ref" />
Expand Down
8 changes: 8 additions & 0 deletions docs/rules/no-array-index-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ things.reduce((collection, thing, index) => (
things.reduceRight((collection, thing, index) => (
collection.concat(<Hello key={index} />)
), []);

React.Children.map(this.props.children, (child, index) => (
React.cloneElement(child, { key: index })
))

Children.forEach(this.props.children, (child, index) => (
React.cloneElement(child, { key: index })
))
```

The following patterns are **not** considered warnings:
Expand Down
27 changes: 0 additions & 27 deletions docs/rules/no-deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ const propTypes = {
React.DOM.div();

import React, { PropTypes } from 'react';

class Foo extends React.Component {
componentWillMount() { }
componentWillReceiveProps() { }
componentWillUpdate() { }
// ...
}

class Foo extends React.PureComponent {
componentWillMount() { }
componentWillReceiveProps() { }
componentWillUpdate() { }
// ...
}

var Foo = createReactClass({
componentWillMount: function() {},
componentWillReceiveProps: function() {},
componentWillUpdate: function() {},
// ...
})
```

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

import { PropTypes } from 'prop-types';

class Foo {
componentWillMount() { }
componentWillReceiveProps() { }
componentWillUpdate() { }
}
```
4 changes: 2 additions & 2 deletions docs/rules/no-unescaped-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ when the closing `>` is in the wrong place.
The preferred way to include one of these characters is to use the HTML escape code.

- `>` can be replaced with `&gt;`
- `"` can be replaced with `&quot;`, `&ldquo;` or `&rdquo;`
- `'` can be replaced with `&apos;`, `&lsquo;` or `&rsquo;`
- `"` can be replaced with `&quot;`, `&ldquo;`, `&#34;` or `&rdquo;`
- `'` can be replaced with `&apos;`, `&lsquo;`, `&#39;` or `&rsquo;`
- `}` can be replaced with `&#125;`

Alternatively, you can include the literal character inside a subexpression
Expand Down

0 comments on commit acc35a1

Please sign in to comment.