@@ -13,6 +13,9 @@ var ComponentList = componentUtil.List;
13
13
14
14
module . exports = function ( context ) {
15
15
16
+ var configuration = context . options [ 0 ] || { } ;
17
+ var ignored = configuration . ignore || [ ] ;
18
+
16
19
var componentList = new ComponentList ( ) ;
17
20
18
21
var MISSING_MESSAGE = '\'{{name}}\' is missing in props validation' ;
@@ -42,6 +45,28 @@ module.exports = function(context) {
42
45
) ;
43
46
}
44
47
48
+ /**
49
+ * Checks if the prop is ignored
50
+ * @param {String } name Name of the prop to check.
51
+ * @returns {Boolean } True if the prop is ignored, false if not.
52
+ */
53
+ function isIgnored ( name ) {
54
+ return ignored . indexOf ( name ) !== - 1 ;
55
+ }
56
+
57
+ /**
58
+ * Checks if the prop is declared
59
+ * @param {String } name Name of the prop to check.
60
+ * @param {Object } component The component to process
61
+ * @returns {Boolean } True if the prop is declared, false if not.
62
+ */
63
+ function isDeclaredInComponent ( component , name ) {
64
+ return (
65
+ component . declaredPropTypes &&
66
+ component . declaredPropTypes . indexOf ( name ) !== - 1
67
+ ) ;
68
+ }
69
+
45
70
/**
46
71
* Mark a prop type as used
47
72
* @param {ASTNode } node The AST node being marked.
@@ -117,25 +142,22 @@ module.exports = function(context) {
117
142
118
143
/**
119
144
* Reports undeclared proptypes for a given component
120
- * @param {Object } id The component to process
145
+ * @param {Object } component The component to process
121
146
*/
122
147
function reportUndeclaredPropTypes ( component ) {
123
148
if ( ! component || ! component . usedPropTypes || component . ignorePropsValidation === true ) {
124
149
return ;
125
150
}
151
+ var name ;
126
152
for ( var i = 0 , j = component . usedPropTypes . length ; i < j ; i ++ ) {
127
- var isDeclared =
128
- component . declaredPropTypes &&
129
- component . declaredPropTypes . indexOf ( component . usedPropTypes [ i ] . name ) !== - 1
130
- ;
131
- var isChildren = component . usedPropTypes [ i ] . name === 'children' ;
132
- if ( isDeclared || isChildren ) {
153
+ name = component . usedPropTypes [ i ] . name ;
154
+ if ( isDeclaredInComponent ( component , name ) || isIgnored ( name ) ) {
133
155
continue ;
134
156
}
135
157
context . report (
136
158
component . usedPropTypes [ i ] . node ,
137
159
component . name === componentUtil . DEFAULT_COMPONENT_NAME ? MISSING_MESSAGE : MISSING_MESSAGE_NAMED_COMP , {
138
- name : component . usedPropTypes [ i ] . name ,
160
+ name : name ,
139
161
component : component . name
140
162
}
141
163
) ;
0 commit comments