@@ -95,9 +95,9 @@ module.exports = {
9595
9696 /**
9797 * @param {ComponentProp[] } props
98- * @param { { [key : string]: Property | undefined } } [withDefaultsProps ]
98+ * @param {(fixer: RuleFixer, propName : string, replaceKeyText: string) => Iterable<Fix> } [fixPropInOtherPlaces ]
9999 */
100- function processProps ( props , withDefaultsProps ) {
100+ function processProps ( props , fixPropInOtherPlaces ) {
101101 for ( const prop of props ) {
102102 if ( ! prop . propName ) {
103103 continue
@@ -118,7 +118,14 @@ module.exports = {
118118 : createSuggest (
119119 prop . key ,
120120 option ,
121- withDefaultsProps && withDefaultsProps [ prop . propName ]
121+ fixPropInOtherPlaces
122+ ? ( fixer , replaceKeyText ) =>
123+ fixPropInOtherPlaces (
124+ fixer ,
125+ prop . propName ,
126+ replaceKeyText
127+ )
128+ : undefined
122129 )
123130 } )
124131 break
@@ -129,7 +136,33 @@ module.exports = {
129136 return utils . compositingVisitors (
130137 utils . defineScriptSetupVisitor ( context , {
131138 onDefinePropsEnter ( node , props ) {
132- processProps ( props , utils . getWithDefaultsProps ( node ) )
139+ processProps ( props , fixPropInOtherPlaces )
140+
141+ /**
142+ * @param {RuleFixer } fixer
143+ * @param {string } propName
144+ * @param {string } replaceKeyText
145+ */
146+ function fixPropInOtherPlaces ( fixer , propName , replaceKeyText ) {
147+ /** @type {(Property|AssignmentProperty)[] } */
148+ const propertyNodes = [ ]
149+ const withDefault = utils . getWithDefaultsProps ( node ) [ propName ]
150+ if ( withDefault ) {
151+ propertyNodes . push ( withDefault )
152+ }
153+ const propDestructure = utils . getPropsDestructure ( node ) [ propName ]
154+ if ( propDestructure ) {
155+ propertyNodes . push ( propDestructure )
156+ }
157+ return propertyNodes . map ( ( propertyNode ) =>
158+ propertyNode . shorthand
159+ ? fixer . insertTextBefore (
160+ propertyNode . value ,
161+ `${ replaceKeyText } :`
162+ )
163+ : fixer . replaceText ( propertyNode . key , replaceKeyText )
164+ )
165+ }
133166 }
134167 } ) ,
135168 utils . defineVueVisitor ( context , {
@@ -144,10 +177,10 @@ module.exports = {
144177/**
145178 * @param {Expression } node
146179 * @param {ParsedOption } option
147- * @param {Property } [withDefault ]
180+ * @param {(fixer: RuleFixer, replaceKeyText: string) => Iterable<Fix> } [fixPropInOtherPlaces ]
148181 * @returns {Rule.SuggestionReportDescriptor[] }
149182 */
150- function createSuggest ( node , option , withDefault ) {
183+ function createSuggest ( node , option , fixPropInOtherPlaces ) {
151184 if ( ! option . suggest ) {
152185 return [ ]
153186 }
@@ -168,14 +201,8 @@ function createSuggest(node, option, withDefault) {
168201 {
169202 fix ( fixer ) {
170203 const fixes = [ fixer . replaceText ( node , replaceText ) ]
171- if ( withDefault ) {
172- if ( withDefault . shorthand ) {
173- fixes . push (
174- fixer . insertTextBefore ( withDefault . value , `${ replaceText } :` )
175- )
176- } else {
177- fixes . push ( fixer . replaceText ( withDefault . key , replaceText ) )
178- }
204+ if ( fixPropInOtherPlaces ) {
205+ fixes . push ( ...fixPropInOtherPlaces ( fixer , replaceText ) )
179206 }
180207 return fixes . sort ( ( a , b ) => a . range [ 0 ] - b . range [ 0 ] )
181208 } ,
0 commit comments