-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into typo-prefer-es6-c…
…lass
- Loading branch information
Showing
18 changed files
with
1,170 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.