@@ -95,9 +95,9 @@ module.exports = {
95
95
96
96
/**
97
97
* @param {ComponentProp[] } props
98
- * @param { { [key : string]: Property | undefined } } [withDefaultsProps ]
98
+ * @param {(fixer: RuleFixer, propName : string, replaceKeyText: string) => Iterable<Fix> } [fixPropInOtherPlaces ]
99
99
*/
100
- function processProps ( props , withDefaultsProps ) {
100
+ function processProps ( props , fixPropInOtherPlaces ) {
101
101
for ( const prop of props ) {
102
102
if ( ! prop . propName ) {
103
103
continue
@@ -118,7 +118,14 @@ module.exports = {
118
118
: createSuggest (
119
119
prop . key ,
120
120
option ,
121
- withDefaultsProps && withDefaultsProps [ prop . propName ]
121
+ fixPropInOtherPlaces
122
+ ? ( fixer , replaceKeyText ) =>
123
+ fixPropInOtherPlaces (
124
+ fixer ,
125
+ prop . propName ,
126
+ replaceKeyText
127
+ )
128
+ : undefined
122
129
)
123
130
} )
124
131
break
@@ -129,7 +136,33 @@ module.exports = {
129
136
return utils . compositingVisitors (
130
137
utils . defineScriptSetupVisitor ( context , {
131
138
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
+ }
133
166
}
134
167
} ) ,
135
168
utils . defineVueVisitor ( context , {
@@ -144,10 +177,10 @@ module.exports = {
144
177
/**
145
178
* @param {Expression } node
146
179
* @param {ParsedOption } option
147
- * @param {Property } [withDefault ]
180
+ * @param {(fixer: RuleFixer, replaceKeyText: string) => Iterable<Fix> } [fixPropInOtherPlaces ]
148
181
* @returns {Rule.SuggestionReportDescriptor[] }
149
182
*/
150
- function createSuggest ( node , option , withDefault ) {
183
+ function createSuggest ( node , option , fixPropInOtherPlaces ) {
151
184
if ( ! option . suggest ) {
152
185
return [ ]
153
186
}
@@ -168,14 +201,8 @@ function createSuggest(node, option, withDefault) {
168
201
{
169
202
fix ( fixer ) {
170
203
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 ) )
179
206
}
180
207
return fixes . sort ( ( a , b ) => a . range [ 0 ] - b . range [ 0 ] )
181
208
} ,
0 commit comments