@@ -150,19 +150,26 @@ module.exports = {
150
150
* Get the characters used for indentation on the line to be matched
151
151
* @param {Object } tokens Locations of the opening bracket, closing bracket and last prop
152
152
* @param {String } expectedLocation Expected location for the closing bracket
153
+ * @param {Number } correctColumn Expected column for the closing bracket
153
154
* @return {String } The characters used for indentation
154
155
*/
155
- function getIndentation ( tokens , expectedLocation ) {
156
+ function getIndentation ( tokens , expectedLocation , correctColumn ) {
157
+ var indentation , spaces = [ ] ;
156
158
switch ( expectedLocation ) {
157
159
case 'props-aligned' :
158
- return / ^ \s * / . exec ( sourceCode . lines [ tokens . lastProp . lastLine ] ) [ 0 ] ;
160
+ indentation = / ^ \s * / . exec ( sourceCode . lines [ tokens . lastProp . firstLine - 1 ] ) [ 0 ] ;
161
+ break ;
159
162
case 'tag-aligned' :
160
- return / ^ \s * / . exec ( sourceCode . lines [ tokens . opening . line ] ) [ 0 ] ;
161
163
case 'line-aligned' :
162
- return / ^ \s * / . exec ( sourceCode . lines [ tokens . openingStartOfLine . line ] ) [ 0 ] ;
164
+ indentation = / ^ \s * / . exec ( sourceCode . lines [ tokens . opening . line - 1 ] ) [ 0 ] ;
163
165
default :
164
- return '' ;
166
+ indentation = '' ;
165
167
}
168
+ if ( indentation . length + 1 < correctColumn ) {
169
+ // Non-whitespace characters were included in the column offset
170
+ spaces = new Array ( + correctColumn + 1 - indentation . length ) ;
171
+ }
172
+ return indentation + spaces . join ( ' ' ) ;
166
173
}
167
174
168
175
/**
@@ -264,7 +271,7 @@ module.exports = {
264
271
case 'tag-aligned' :
265
272
case 'line-aligned' :
266
273
return fixer . replaceTextRange ( [ cachedLastAttributeEndPos , node . end ] ,
267
- '\n' + getIndentation ( tokens , expectedLocation ) + closingTag ) ;
274
+ '\n' + getIndentation ( tokens , expectedLocation , correctColumn ) + closingTag ) ;
268
275
default :
269
276
return true ;
270
277
}
0 commit comments