77/**
88 * @typedef {import('../utils').ComponentProp } ComponentProp
99 * @typedef {import('../utils').ComponentObjectProp } ComponentObjectProp
10+ * @typedef {import('../utils').ComponentTypeProp } ComponentTypeProp
1011 * @typedef {ComponentObjectProp & { value: ObjectExpression} } ComponentObjectPropObject
1112 */
1213
@@ -137,18 +138,23 @@ module.exports = {
137138
138139 /**
139140 * @param {ComponentProp[] } props
140- * @param {boolean } [withDefaults]
141- * @param { { [key: string]: Expression | undefined } } [withDefaultsExpressions]
141+ * @param {(prop: ComponentObjectProp|ComponentTypeProp)=>boolean } [ignore]
142142 */
143- function processProps ( props , withDefaults , withDefaultsExpressions ) {
143+ function processProps ( props , ignore ) {
144144 for ( const prop of props ) {
145- if ( prop . type === 'object' && ! prop . node . shorthand ) {
145+ if ( prop . type === 'object' ) {
146+ if ( prop . node . shorthand ) {
147+ continue
148+ }
146149 if ( ! isWithoutDefaultValue ( prop ) ) {
147150 continue
148151 }
149152 if ( isBooleanProp ( prop ) ) {
150153 continue
151154 }
155+ if ( ignore ?. ( prop ) ) {
156+ continue
157+ }
152158 const propName =
153159 prop . propName == null
154160 ? `[${ context . getSourceCode ( ) . getText ( prop . node . key ) } ]`
@@ -161,38 +167,57 @@ module.exports = {
161167 propName
162168 }
163169 } )
164- } else if (
165- prop . type === 'type' &&
166- withDefaults &&
167- withDefaultsExpressions
168- ) {
170+ } else if ( prop . type === 'type' ) {
169171 if ( prop . required ) {
170172 continue
171173 }
172174 if ( prop . types . length === 1 && prop . types [ 0 ] === 'Boolean' ) {
173175 continue
174176 }
175- if ( ! withDefaultsExpressions [ prop . propName ] ) {
176- context . report ( {
177- node : prop . node ,
178- messageId : `missingDefault` ,
179- data : {
180- propName : prop . propName
181- }
182- } )
177+ if ( ignore ?. ( prop ) ) {
178+ continue
183179 }
180+ context . report ( {
181+ node : prop . node ,
182+ messageId : `missingDefault` ,
183+ data : {
184+ propName : prop . propName
185+ }
186+ } )
184187 }
185188 }
186189 }
187190
188191 return utils . compositingVisitors (
189192 utils . defineScriptSetupVisitor ( context , {
190193 onDefinePropsEnter ( node , props ) {
191- processProps (
192- props ,
193- utils . hasWithDefaults ( node ) ,
194+ const hasWithDefaults = utils . hasWithDefaults ( node )
195+ const defaultsByWithDefaults =
194196 utils . getWithDefaultsPropExpressions ( node )
195- )
197+ const isUsingPropsDestructure = utils . isUsingPropsDestructure ( node )
198+ const defaultsByAssignmentPatterns =
199+ utils . getDefaultPropExpressionsForPropsDestructure ( node )
200+
201+ processProps ( props , ( prop ) => {
202+ if ( prop . type === 'type' ) {
203+ if ( ! hasWithDefaults ) {
204+ // If don't use withDefaults(), exclude it from the report.
205+ return true
206+ }
207+ if ( defaultsByWithDefaults [ prop . propName ] ) {
208+ return true
209+ }
210+ }
211+ if ( ! isUsingPropsDestructure ) {
212+ return false
213+ }
214+ if ( prop . propName == null ) {
215+ // If using Props Destructure but the property name cannot be determined,
216+ // it will be ignored.
217+ return true
218+ }
219+ return Boolean ( defaultsByAssignmentPatterns [ prop . propName ] )
220+ } )
196221 }
197222 } ) ,
198223 utils . executeOnVue ( context , ( obj ) => {
0 commit comments