Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into typo-prefer-es6-c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
adnasa committed Feb 19, 2017
2 parents d800229 + 22f3638 commit 6334d63
Show file tree
Hide file tree
Showing 18 changed files with 1,170 additions and 111 deletions.
45 changes: 44 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,47 @@ 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).

## [6.9.0] - 2016-01-08
## [6.10.0] - 2017-02-16
### Added
* Add [`forbid-foreign-prop-types`][] rule ([#696][] @iancmyers)
* Add [`void-dom-elements-no-children`][] rule ([#709][] @lencioni)
* Add [`forbid-elements`][] rule ([#887][] @kentor)
* Add `noSortAlphabetically` option to [`jsx-sort-props`][] ([#541][] [#786][] @markus101)
* Add `when` option to [`jsx-max-props-per-line`][] ([#878][] @kentor)
* Add support for `nextProps` to [`prop-types`][] ([#814][])

### Fixed
* Fix [`require-default-props`][] crash ([#1029][])
* Fix [`require-default-props`][] rule when using Flow type from assignment ([#1043][] @wyze @CarlRosell)
* Fix [`style-prop-object`][] to not warn with explicit `null` or `undefined` ([#812][] @ljharb)
* Fix [`no-unused-prop-types`][] props detection in stateless components ([#885][] @BarryThePenguin)
* Fix [`display-name`] false positive with `document.createElement` ([#996][] @jomasti)
* Fix ESLint 2 compatibility (@ljharb)

### Changed
* Tests improvements (@ljharb)
* Documentation improvements ([#958][] @Jorundur, [#1010][] @amilajack, [#1041][] @EvNaverniouk, [#1050][] @lencioni, [#1062][] @dguo)

[6.10.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v6.9.0...v6.10.0
[#696]: https://github.com/yannickcr/eslint-plugin-react/issues/696
[#709]: https://github.com/yannickcr/eslint-plugin-react/issues/709
[#887]: https://github.com/yannickcr/eslint-plugin-react/issues/887
[#541]: https://github.com/yannickcr/eslint-plugin-react/issues/541
[#786]: https://github.com/yannickcr/eslint-plugin-react/issues/786
[#878]: https://github.com/yannickcr/eslint-plugin-react/issues/878
[#814]: https://github.com/yannickcr/eslint-plugin-react/issues/814
[#1029]: https://github.com/yannickcr/eslint-plugin-react/issues/1029
[#1043]: https://github.com/yannickcr/eslint-plugin-react/issues/1043
[#812]: https://github.com/yannickcr/eslint-plugin-react/issues/812
[#885]: https://github.com/yannickcr/eslint-plugin-react/issues/885
[#996]: https://github.com/yannickcr/eslint-plugin-react/issues/996
[#958]: https://github.com/yannickcr/eslint-plugin-react/pull/958
[#1010]: https://github.com/yannickcr/eslint-plugin-react/pull/1010
[#1041]: https://github.com/yannickcr/eslint-plugin-react/pull/1041
[#1050]: https://github.com/yannickcr/eslint-plugin-react/pull/1050
[#1062]: https://github.com/yannickcr/eslint-plugin-react/pull/1062

## [6.9.0] - 2017-01-08
### Added
* Add support for variable reference to [`sort-prop-types`][] ([#622][])

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

[`display-name`]: docs/rules/display-name.md
[`forbid-component-props`]: docs/rules/forbid-component-props.md
[`forbid-elements`]: docs/rules/forbid-elements.md
[`forbid-foreign-prop-types`]: docs/rules/forbid-foreign-prop-types.md
[`forbid-prop-types`]: docs/rules/forbid-prop-types.md
[`no-array-index-key`]: docs/rules/no-array-index-key.md
[`no-children-prop`]: docs/rules/no-children-prop.md
Expand Down Expand Up @@ -1592,6 +1634,7 @@ If you're still not using React 15 you can keep the old behavior by setting the
[`jsx-uses-react`]: docs/rules/jsx-uses-react.md
[`jsx-uses-vars`]: docs/rules/jsx-uses-vars.md
[`jsx-wrap-multilines`]: docs/rules/jsx-wrap-multilines.md
[`void-dom-elements-no-children`]: docs/rules/void-dom-elements-no-children.md

[`jsx-sort-prop-types`]: docs/rules/sort-prop-types.md
[`require-extension`]: docs/rules/require-extension.md
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#

* [react/display-name](docs/rules/display-name.md): Prevent missing `displayName` in a React component definition
* [react/forbid-component-props](docs/rules/forbid-component-props.md): Forbid certain props on Components
* [react/forbid-elements](docs/rules/forbid-elements.md): Forbid certain elements
* [react/forbid-prop-types](docs/rules/forbid-prop-types.md): Forbid certain propTypes
* [react/forbid-foreign-prop-types](docs/rules/forbid-foreign-prop-types.md): Forbid foreign propTypes
* [react/no-array-index-key](docs/rules/no-array-index-key.md): Prevent using Array index in `key` props
* [react/no-children-prop](docs/rules/no-children-prop.md): Prevent passing children as props
* [react/no-danger](docs/rules/no-danger.md): Prevent usage of dangerous JSX properties
Expand Down
58 changes: 58 additions & 0 deletions docs/rules/forbid-elements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Forbid certain elements (forbid-elements)

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.

## Rule Details

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.

## Rule Options

```js
...
"forbid-elements": [<enabled>, { "forbid": [<string|object>] }]
...
```

### `forbid`

An array of strings and/or objects. An object in this array may have the following properties:

* `element` (required): the name of the forbidden element (e.g. `'button'`, `'Modal'`)
* `message`: additional message that gets reported

A string item in the array is a shorthand for `{ element: string }`.

The following patterns are not considered warnings:

```jsx
// [1, { "forbid": ["button"] }]
<Button />

// [1, { "forbid": [{ "element": "button" }] }]
<Button />
```

The following patterns are considered warnings:

```jsx
// [1, { "forbid": ["button"] }]
<button />
React.createElement('button');

// [1, { "forbid": ["Modal"] }]
<Modal />
React.createElement(Modal);

// [1, { "forbid": ["Namespaced.Element"] }]
<Namespaced.Element />
React.createElement(Namespaced.Element);

// [1, { "forbid": [{ "element": "button", "message": "use <Button> instead" }, "input"] }]
<div><button /><input /></div>
React.createElement('div', {}, React.createElemet('button', {}, React.createElement('input')));
```

## When not to use

If you don't want to forbid any elements.
30 changes: 30 additions & 0 deletions docs/rules/forbid-foreign-prop-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Forbid foreign propTypes (forbid-foreign-prop-types)

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.

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.

## Rule Details

This rule checks all objects and ensures that the `propTypes` property is not used.

The following patterns are considered warnings:

```js
import SomeComponent from './SomeComponent';
SomeComponent.propTypes;

var { propTypes } = SomeComponent;

SomeComponent['propTypes'];
```

The following patterns are not considered warnings:

```js
import SomeComponent, {propTypes as someComponentPropTypes} from './SomeComponent';
```

## When not to use

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.
62 changes: 62 additions & 0 deletions docs/rules/jsx-indent.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,68 @@ The following patterns are not warnings:
</App>
```

#### indentLogicalExpressions

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

By default this is set to false. When enabled, an additional indentation is required when the JSX is the right of a LogicalExpression

The following patterns are considered warnings:

```jsx
// 2 spaces indentation with indentLogicalExpressions as false
// [2, 2, {indentLogicalExpressions: false}]
<App>
{
condition &&
<Container>
<Child></Child>
</Container>
}
</App>

// 2 spaces indentation with indentLogicalExpressions as true
// [2, 2, {indentLogicalExpressions: true}]
<App>
{
condition &&
<Container>
<Child></Child>
</Container>
}
</App>
```

The following patterns are not warnings:

```jsx
// 2 spaces indentation with indentLogicalExpressions as true
// [2, 2, {indentLogicalExpressions: true}]
<App>
{
condition &&
<Container>
<Child></Child>
</Container>
}
</App>

// 2 spaces indentation with indentLogicalExpressions as false
// [2, 2, {indentLogicalExpressions: false}]
<App>
{
condition &&
<Container>
<Child></Child>
</Container>
}
</App>
```

## When not to use

If you are not using JSX then you can disable this rule.
34 changes: 30 additions & 4 deletions docs/rules/jsx-max-props-per-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ Limiting the maximum of props on a single line can improve readability.

## Rule Details

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

The following patterns are considered warnings:

```jsx
<Hello lastName="Smith" firstName="John" />;

<Hello foo={{
bar
}} baz />;
```

The following patterns are not considered warnings:
Expand All @@ -31,7 +35,7 @@ The following patterns are not considered warnings:

```js
...
"react/jsx-max-props-per-line": [<enabled>, { "maximum": <number> }]
"react/jsx-max-props-per-line": [<enabled>, { "maximum": <number>, "when": <string> }]
...
```

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

```jsx
// [1, {maximum: 2}]
// [1, { "maximum": 2 }]
<Hello firstName="John" lastName="Smith" tel={5555555} />;
```

The following patterns are not considered warnings:

```jsx
// [1, {maximum: 2}]
// [1, { "maximum": 2 }]
<Hello
firstName="John" lastName="Smith"
tel={5555555}
/>;
```

### `when`

Possible values:
- `always` (default) - Always check for max props per line.
- `multiline` - Only check for max props per line when jsx tag spans multiple lines.

The following patterns are considered warnings:
```jsx
// [1, { "when": "always" }]
<Hello firstName="John" lastName="Smith" />
```

The following patterns are not considered warnings:
```jsx
// [1, { "when": "multiline" }]
<Hello firstName="John" lastName="Smith" />
<Hello
firstName="John"
lastName="Smith"
/>
```

## When not to use

If you are not using JSX then you can disable this rule.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ var allRules = {
'jsx-space-before-closing': require('./lib/rules/jsx-space-before-closing'),
'no-direct-mutation-state': require('./lib/rules/no-direct-mutation-state'),
'forbid-component-props': require('./lib/rules/forbid-component-props'),
'forbid-elements': require('./lib/rules/forbid-elements'),
'forbid-prop-types': require('./lib/rules/forbid-prop-types'),
'forbid-foreign-prop-types': require('./lib/rules/forbid-foreign-prop-types'),
'prefer-es6-class': require('./lib/rules/prefer-es6-class'),
'jsx-key': require('./lib/rules/jsx-key'),
'no-string-refs': require('./lib/rules/no-string-refs'),
Expand Down

0 comments on commit 6334d63

Please sign in to comment.