@@ -106,6 +106,13 @@ module.exports = {
106
106
} ) ;
107
107
}
108
108
109
+ function isPropWithNoDefaulVal ( prop ) {
110
+ if ( prop . type === 'RestElement' || prop . type === 'ExperimentalRestProperty' ) {
111
+ return false ;
112
+ }
113
+ return prop . value . type !== 'AssignmentPattern' ;
114
+ }
115
+
109
116
/**
110
117
* If functions option is 'defaultArguments', reports defaultProps is used and all params that doesn't initialized.
111
118
* @param {Object } componentNode Node of component.
@@ -134,15 +141,23 @@ module.exports = {
134
141
} ) ;
135
142
}
136
143
} else if ( props . type === 'ObjectPattern' ) {
144
+ // Filter required props with default value and report error
137
145
props . properties . filter ( ( prop ) => {
138
- if ( prop . type === 'RestElement' || prop . type === 'ExperimentalRestProperty' ) {
139
- return false ;
140
- }
141
- const propType = propTypes [ prop . key . name ] ;
142
- if ( ! propType || propType . isRequired ) {
143
- return false ;
144
- }
145
- return prop . value . type !== 'AssignmentPattern' ;
146
+ const propName = prop && prop . key && prop . key . name ;
147
+ const isPropRequired = propTypes [ propName ] && propTypes [ propName ] . isRequired ;
148
+ return propTypes [ propName ] && isPropRequired && ! isPropWithNoDefaulVal ( prop ) ;
149
+ } ) . forEach ( ( prop ) => {
150
+ report ( context , messages . noDefaultWithRequired , 'noDefaultWithRequired' , {
151
+ node : prop ,
152
+ data : { name : prop . key . name } ,
153
+ } ) ;
154
+ } ) ;
155
+
156
+ // Filter non required props with no default value and report error
157
+ props . properties . filter ( ( prop ) => {
158
+ const propName = prop && prop . key && prop . key . name ;
159
+ const isPropRequired = propTypes [ propName ] && propTypes [ propName ] . isRequired ;
160
+ return propTypes [ propName ] && ! isPropRequired && isPropWithNoDefaulVal ( prop ) ;
146
161
} ) . forEach ( ( prop ) => {
147
162
report ( context , messages . shouldAssignObjectDefault , 'shouldAssignObjectDefault' , {
148
163
node : prop ,
0 commit comments