@@ -57,11 +57,14 @@ This rule can take one argument to ignore some specific props during validation.
57
57
58
58
## Known Issues/Limitations
59
59
60
- *** False positives*** for components with Stateless Functional Components;
60
+ - [ False Positives: SFC (helper render methods)] ( #false-positives-sfc )
61
+ - [ False Positives: Intermediate variables] ( #false-positives-intermediate-variables )
62
+
63
+ ### False positives SFC
64
+ For components with Stateless Functional Components (often used as helper render methods);
61
65
SFC is a function that takes prop(s) as an argument and returns a JSX expression.
62
66
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.
63
67
64
-
65
68
Triggers false positive:
66
69
``` js
67
70
function AComponent (props ) {
@@ -106,3 +109,50 @@ AComponent.propTypes = {
106
109
bProp: PropTypes .string
107
110
};
108
111
```
112
+
113
+ ### False positives intermediate variables
114
+ when assigning a part or a whole props object to a variable and using it to access a prop value.
115
+
116
+ ``` js
117
+ class AComponent extends React .Component {
118
+ render () {
119
+ const { props } = this ;
120
+
121
+ return < div> {props .aProp }< / div> ;
122
+ }
123
+ }
124
+ AComponent .propTypes = {
125
+ aProp: PropTypes .string // aProp PropType is defined but prop is never used
126
+ };
127
+ ```
128
+
129
+ suggested code structure to avoid the issue:
130
+
131
+ - accessing prop directly
132
+ ``` js
133
+ class AComponent extends React .Component {
134
+ render () {
135
+ return < div> {this .props .aProp }< / div> ;
136
+ }
137
+ }
138
+ AComponent .propTypes = {
139
+ aProp: PropTypes .string
140
+ };
141
+ ```
142
+
143
+ - or assigning a final prop to a variable.
144
+
145
+ ``` js
146
+ class AComponent extends React .Component {
147
+ const { aProp } = this .props ;
148
+ render () {
149
+ return < div> {aProp}< / div> ;
150
+ }
151
+ }
152
+ AComponent .propTypes = {
153
+ aProp: PropTypes .string
154
+ };
155
+ ```
156
+
157
+ Using Intermediate variables might be desired and unavoidable for more complex props structure.
158
+ Like for shape prop types. To avoid false positive in this case make sure ` skipShapeProps ` is set to ` true ` .
0 commit comments