Skip to content

Commit

Permalink
[Docs] forbid-foreign-prop-types: document allowInPropTypes option
Browse files Browse the repository at this point in the history
Fixes #1815
  • Loading branch information
ljharb committed Feb 6, 2022
1 parent 42a8093 commit 2e6a391
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -28,6 +28,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [Docs] [`jsx-no-target-blank`]: Improve readme ([#3169][] @apepper)
* [Docs] [`display-name`]: improve examples ([#3189][] @golopot)
* [Refactor] [`no-invalid-html-attribute`]: sort HTML_ELEMENTS and messages ([#3182][] @Primajin)
* [Docs] [`forbid-foreign-prop-types`]: document `allowInPropTypes` option ([#1815][] @ljharb)

[#3195]: https://github.com/yannickcr/eslint-plugin-react/pull/3195
[#3191]: https://github.com/yannickcr/eslint-plugin-react/pull/3191
Expand All @@ -43,6 +44,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
[#3133]: https://github.com/yannickcr/eslint-plugin-react/pull/3133
[#2921]: https://github.com/yannickcr/eslint-plugin-react/pull/2921
[#2753]: https://github.com/yannickcr/eslint-plugin-react/pull/2753
[#1815]: https://github.com/yannickcr/eslint-plugin-react/issues/1815
[#1754]: https://github.com/yannickcr/eslint-plugin-react/issues/1754
[#1046]: https://github.com/yannickcr/eslint-plugin-react/issues/1046
[#620]: https://github.com/yannickcr/eslint-plugin-react/pull/620
Expand Down
14 changes: 13 additions & 1 deletion docs/rules/forbid-foreign-prop-types.md
Expand Up @@ -2,7 +2,7 @@

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.
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/HEAD/docs/rules/named.md) in conjunction with this rule.

## Rule Details

Expand All @@ -25,6 +25,18 @@ Examples of **correct** code for this rule:
import SomeComponent, {propTypes as someComponentPropTypes} from './SomeComponent';
```

## Rule Options

```js
...
"react/forbid-foreign-prop-types": [<enabled>, { "allowInPropTypes": [<boolean>] }]
...
```

### `allowInPropTypes`

If `true`, the rule will not warn on foreign propTypes usage inside a propTypes declaration.

## When Not To Use It

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

0 comments on commit 2e6a391

Please sign in to comment.