You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/no-unused-prop-types.md
+46-8Lines changed: 46 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,16 +55,54 @@ This rule can take one argument to ignore some specific props during validation.
55
55
*`customValidators`: optional array of validators used for propTypes validation.
56
56
*`skipShapeProps`: In some cases it is impossible to accurately detect whether or not a `PropTypes.shape`'s values are being used. Setting this option to `true` will skip validation of `PropTypes.shape` (`true` by default).
57
57
58
-
## Caveats
58
+
## Known Issues/Limitations
59
59
60
-
This rule does not track component props as they move from function to function or during variable renaming (such as in the event of prop object destructuring assignments). As such, it's prone to false positives in situations where the prop use cannot be accurately detected.
60
+
***False positives*** for components with Stateless Functional Components;
61
+
SFC is a function that takes prop(s) as an argument and returns a JSX expression.
62
+
Even if this function gets called from a component the props that are only used inside SFC would not be considered used by a component.
61
63
62
-
## About component detection
63
64
64
-
For this rule to work we need to detect React components, this could be very hard since components could be declared in a lot of ways.
65
+
Triggers false positive:
66
+
```js
67
+
functionAComponent(props) {
68
+
functionhelperRenderer(aProp) { // is considered SFC
69
+
return (
70
+
<span>{aProp}{props.bProp}</span>
71
+
);
72
+
}
65
73
66
-
For now we should detect components created with:
74
+
return (
75
+
<div>
76
+
{helperRenderer(props.aProp)}
77
+
</div>
78
+
);
79
+
}
80
+
81
+
AComponent.propTypes= {
82
+
aProp:PropTypes.string,
83
+
bProp:PropTypes.string// bProp is defined but never used
84
+
};
85
+
```
86
+
A suggested fix is to assign a bProp to a variable outside of the SFC.
67
87
68
-
*`createReactClass()`
69
-
* an ES6 class that inherit from `React.Component` or `Component`
70
-
* a stateless function that return JSX or the result of a `React.createElement` call.
88
+
```js
89
+
functionAComponent(props) {
90
+
const { bProp } = props
91
+
functionhelperRenderer(aProp) { // is considered SFC
0 commit comments