Skip to content

Commit 6334d63

Browse files
committed
Merge remote-tracking branch 'upstream/master' into typo-prefer-es6-class
2 parents d800229 + 22f3638 commit 6334d63

18 files changed

+1170
-111
lines changed

CHANGELOG.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,47 @@ 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-
## [6.9.0] - 2016-01-08
6+
## [6.10.0] - 2017-02-16
7+
### Added
8+
* Add [`forbid-foreign-prop-types`][] rule ([#696][] @iancmyers)
9+
* Add [`void-dom-elements-no-children`][] rule ([#709][] @lencioni)
10+
* Add [`forbid-elements`][] rule ([#887][] @kentor)
11+
* Add `noSortAlphabetically` option to [`jsx-sort-props`][] ([#541][] [#786][] @markus101)
12+
* Add `when` option to [`jsx-max-props-per-line`][] ([#878][] @kentor)
13+
* Add support for `nextProps` to [`prop-types`][] ([#814][])
14+
15+
### Fixed
16+
* Fix [`require-default-props`][] crash ([#1029][])
17+
* Fix [`require-default-props`][] rule when using Flow type from assignment ([#1043][] @wyze @CarlRosell)
18+
* Fix [`style-prop-object`][] to not warn with explicit `null` or `undefined` ([#812][] @ljharb)
19+
* Fix [`no-unused-prop-types`][] props detection in stateless components ([#885][] @BarryThePenguin)
20+
* Fix [`display-name`] false positive with `document.createElement` ([#996][] @jomasti)
21+
* Fix ESLint 2 compatibility (@ljharb)
22+
23+
### Changed
24+
* Tests improvements (@ljharb)
25+
* Documentation improvements ([#958][] @Jorundur, [#1010][] @amilajack, [#1041][] @EvNaverniouk, [#1050][] @lencioni, [#1062][] @dguo)
26+
27+
[6.10.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v6.9.0...v6.10.0
28+
[#696]: https://github.com/yannickcr/eslint-plugin-react/issues/696
29+
[#709]: https://github.com/yannickcr/eslint-plugin-react/issues/709
30+
[#887]: https://github.com/yannickcr/eslint-plugin-react/issues/887
31+
[#541]: https://github.com/yannickcr/eslint-plugin-react/issues/541
32+
[#786]: https://github.com/yannickcr/eslint-plugin-react/issues/786
33+
[#878]: https://github.com/yannickcr/eslint-plugin-react/issues/878
34+
[#814]: https://github.com/yannickcr/eslint-plugin-react/issues/814
35+
[#1029]: https://github.com/yannickcr/eslint-plugin-react/issues/1029
36+
[#1043]: https://github.com/yannickcr/eslint-plugin-react/issues/1043
37+
[#812]: https://github.com/yannickcr/eslint-plugin-react/issues/812
38+
[#885]: https://github.com/yannickcr/eslint-plugin-react/issues/885
39+
[#996]: https://github.com/yannickcr/eslint-plugin-react/issues/996
40+
[#958]: https://github.com/yannickcr/eslint-plugin-react/pull/958
41+
[#1010]: https://github.com/yannickcr/eslint-plugin-react/pull/1010
42+
[#1041]: https://github.com/yannickcr/eslint-plugin-react/pull/1041
43+
[#1050]: https://github.com/yannickcr/eslint-plugin-react/pull/1050
44+
[#1062]: https://github.com/yannickcr/eslint-plugin-react/pull/1062
45+
46+
## [6.9.0] - 2017-01-08
747
### Added
848
* Add support for variable reference to [`sort-prop-types`][] ([#622][])
949

@@ -1539,6 +1579,8 @@ If you're still not using React 15 you can keep the old behavior by setting the
15391579

15401580
[`display-name`]: docs/rules/display-name.md
15411581
[`forbid-component-props`]: docs/rules/forbid-component-props.md
1582+
[`forbid-elements`]: docs/rules/forbid-elements.md
1583+
[`forbid-foreign-prop-types`]: docs/rules/forbid-foreign-prop-types.md
15421584
[`forbid-prop-types`]: docs/rules/forbid-prop-types.md
15431585
[`no-array-index-key`]: docs/rules/no-array-index-key.md
15441586
[`no-children-prop`]: docs/rules/no-children-prop.md
@@ -1592,6 +1634,7 @@ If you're still not using React 15 you can keep the old behavior by setting the
15921634
[`jsx-uses-react`]: docs/rules/jsx-uses-react.md
15931635
[`jsx-uses-vars`]: docs/rules/jsx-uses-vars.md
15941636
[`jsx-wrap-multilines`]: docs/rules/jsx-wrap-multilines.md
1637+
[`void-dom-elements-no-children`]: docs/rules/void-dom-elements-no-children.md
15951638

15961639
[`jsx-sort-prop-types`]: docs/rules/sort-prop-types.md
15971640
[`require-extension`]: docs/rules/require-extension.md

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
8282

8383
* [react/display-name](docs/rules/display-name.md): Prevent missing `displayName` in a React component definition
8484
* [react/forbid-component-props](docs/rules/forbid-component-props.md): Forbid certain props on Components
85+
* [react/forbid-elements](docs/rules/forbid-elements.md): Forbid certain elements
8586
* [react/forbid-prop-types](docs/rules/forbid-prop-types.md): Forbid certain propTypes
87+
* [react/forbid-foreign-prop-types](docs/rules/forbid-foreign-prop-types.md): Forbid foreign propTypes
8688
* [react/no-array-index-key](docs/rules/no-array-index-key.md): Prevent using Array index in `key` props
8789
* [react/no-children-prop](docs/rules/no-children-prop.md): Prevent passing children as props
8890
* [react/no-danger](docs/rules/no-danger.md): Prevent usage of dangerous JSX properties

docs/rules/forbid-elements.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Forbid certain elements (forbid-elements)
2+
3+
You may want to forbid usage of certain elements in favor of others, (e.g. forbid all `<div />` and use `<Box />` instead). This rule allows you to configure a list of forbidden elements and to specify their desired replacements.
4+
5+
## Rule Details
6+
7+
This rule checks all JSX elements and `React.createElement` calls and verifies that no forbidden elements are used. This rule is off by default. If on, no elements are forbidden by default.
8+
9+
## Rule Options
10+
11+
```js
12+
...
13+
"forbid-elements": [<enabled>, { "forbid": [<string|object>] }]
14+
...
15+
```
16+
17+
### `forbid`
18+
19+
An array of strings and/or objects. An object in this array may have the following properties:
20+
21+
* `element` (required): the name of the forbidden element (e.g. `'button'`, `'Modal'`)
22+
* `message`: additional message that gets reported
23+
24+
A string item in the array is a shorthand for `{ element: string }`.
25+
26+
The following patterns are not considered warnings:
27+
28+
```jsx
29+
// [1, { "forbid": ["button"] }]
30+
<Button />
31+
32+
// [1, { "forbid": [{ "element": "button" }] }]
33+
<Button />
34+
```
35+
36+
The following patterns are considered warnings:
37+
38+
```jsx
39+
// [1, { "forbid": ["button"] }]
40+
<button />
41+
React.createElement('button');
42+
43+
// [1, { "forbid": ["Modal"] }]
44+
<Modal />
45+
React.createElement(Modal);
46+
47+
// [1, { "forbid": ["Namespaced.Element"] }]
48+
<Namespaced.Element />
49+
React.createElement(Namespaced.Element);
50+
51+
// [1, { "forbid": [{ "element": "button", "message": "use <Button> instead" }, "input"] }]
52+
<div><button /><input /></div>
53+
React.createElement('div', {}, React.createElemet('button', {}, React.createElement('input')));
54+
```
55+
56+
## When not to use
57+
58+
If you don't want to forbid any elements.
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Forbid foreign propTypes (forbid-foreign-prop-types)
2+
3+
This rule forbids using another component's prop types unless they are explicitly imported/exported. This allows people who want to use [babel-plugin-transform-react-remove-prop-types](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) to remove propTypes from their components in production builds, to do so safely.
4+
5+
In order to ensure that imports are explicitly exported it is recommended to use the ["named" rule in eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md) in conjunction with this rule.
6+
7+
## Rule Details
8+
9+
This rule checks all objects and ensures that the `propTypes` property is not used.
10+
11+
The following patterns are considered warnings:
12+
13+
```js
14+
import SomeComponent from './SomeComponent';
15+
SomeComponent.propTypes;
16+
17+
var { propTypes } = SomeComponent;
18+
19+
SomeComponent['propTypes'];
20+
```
21+
22+
The following patterns are not considered warnings:
23+
24+
```js
25+
import SomeComponent, {propTypes as someComponentPropTypes} from './SomeComponent';
26+
```
27+
28+
## When not to use
29+
30+
This rule aims to make a certain production optimization, removing prop types, less prone to error. This rule may not be relevant to you if you do not wish to make use of this optimization.

docs/rules/jsx-indent.md

+62
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,68 @@ The following patterns are not warnings:
7777
</App>
7878
```
7979

80+
#### indentLogicalExpressions
81+
82+
```js
83+
...
84+
"react/jsx-indent": [<enabled>, 'tab'|<number>, {indentLogicalExpressions: true}]
85+
...
86+
```
87+
88+
By default this is set to false. When enabled, an additional indentation is required when the JSX is the right of a LogicalExpression
89+
90+
The following patterns are considered warnings:
91+
92+
```jsx
93+
// 2 spaces indentation with indentLogicalExpressions as false
94+
// [2, 2, {indentLogicalExpressions: false}]
95+
<App>
96+
{
97+
condition &&
98+
<Container>
99+
<Child></Child>
100+
</Container>
101+
}
102+
</App>
103+
104+
// 2 spaces indentation with indentLogicalExpressions as true
105+
// [2, 2, {indentLogicalExpressions: true}]
106+
<App>
107+
{
108+
condition &&
109+
<Container>
110+
<Child></Child>
111+
</Container>
112+
}
113+
</App>
114+
```
115+
116+
The following patterns are not warnings:
117+
118+
```jsx
119+
// 2 spaces indentation with indentLogicalExpressions as true
120+
// [2, 2, {indentLogicalExpressions: true}]
121+
<App>
122+
{
123+
condition &&
124+
<Container>
125+
<Child></Child>
126+
</Container>
127+
}
128+
</App>
129+
130+
// 2 spaces indentation with indentLogicalExpressions as false
131+
// [2, 2, {indentLogicalExpressions: false}]
132+
<App>
133+
{
134+
condition &&
135+
<Container>
136+
<Child></Child>
137+
</Container>
138+
}
139+
</App>
140+
```
141+
80142
## When not to use
81143

82144
If you are not using JSX then you can disable this rule.

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ Limiting the maximum of props on a single line can improve readability.
44

55
## Rule Details
66

7-
This rule checks all JSX elements and verifies that the number of props per line do not exceed the maximum allowed. A spread attribute counts as one prop. This rule is off by default and when on the default maximum of props on one line is `1`.
7+
This rule checks all JSX elements and verifies that the number of props per line do not exceed the maximum allowed. Props are considered to be in a new line if there is a line break between the start of the prop and the end of the previous prop. A spread attribute counts as one prop. This rule is off by default and when on the default maximum of props on one line is `1`.
88

99
The following patterns are considered warnings:
1010

1111
```jsx
1212
<Hello lastName="Smith" firstName="John" />;
13+
14+
<Hello foo={{
15+
bar
16+
}} baz />;
1317
```
1418

1519
The following patterns are not considered warnings:
@@ -31,7 +35,7 @@ The following patterns are not considered warnings:
3135

3236
```js
3337
...
34-
"react/jsx-max-props-per-line": [<enabled>, { "maximum": <number> }]
38+
"react/jsx-max-props-per-line": [<enabled>, { "maximum": <number>, "when": <string> }]
3539
...
3640
```
3741

@@ -42,20 +46,42 @@ Maximum number of props allowed on a single line. Default to `1`.
4246
The following patterns are considered warnings:
4347

4448
```jsx
45-
// [1, {maximum: 2}]
49+
// [1, { "maximum": 2 }]
4650
<Hello firstName="John" lastName="Smith" tel={5555555} />;
4751
```
4852

4953
The following patterns are not considered warnings:
5054

5155
```jsx
52-
// [1, {maximum: 2}]
56+
// [1, { "maximum": 2 }]
5357
<Hello
5458
firstName="John" lastName="Smith"
5559
tel={5555555}
5660
/>;
5761
```
5862

63+
### `when`
64+
65+
Possible values:
66+
- `always` (default) - Always check for max props per line.
67+
- `multiline` - Only check for max props per line when jsx tag spans multiple lines.
68+
69+
The following patterns are considered warnings:
70+
```jsx
71+
// [1, { "when": "always" }]
72+
<Hello firstName="John" lastName="Smith" />
73+
```
74+
75+
The following patterns are not considered warnings:
76+
```jsx
77+
// [1, { "when": "multiline" }]
78+
<Hello firstName="John" lastName="Smith" />
79+
<Hello
80+
firstName="John"
81+
lastName="Smith"
82+
/>
83+
```
84+
5985
## When not to use
6086

6187
If you are not using JSX then you can disable this rule.

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ var allRules = {
4242
'jsx-space-before-closing': require('./lib/rules/jsx-space-before-closing'),
4343
'no-direct-mutation-state': require('./lib/rules/no-direct-mutation-state'),
4444
'forbid-component-props': require('./lib/rules/forbid-component-props'),
45+
'forbid-elements': require('./lib/rules/forbid-elements'),
4546
'forbid-prop-types': require('./lib/rules/forbid-prop-types'),
47+
'forbid-foreign-prop-types': require('./lib/rules/forbid-foreign-prop-types'),
4648
'prefer-es6-class': require('./lib/rules/prefer-es6-class'),
4749
'jsx-key': require('./lib/rules/jsx-key'),
4850
'no-string-refs': require('./lib/rules/no-string-refs'),

0 commit comments

Comments
 (0)