Skip to content

Commit 3bff9b2

Browse files
committed
Update: applying multiple autofixes simultaneously.
1 parent 8cdb6d5 commit 3bff9b2

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

lib/rules/test-case-property-ordering.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,18 @@ module.exports = {
5757
message,
5858
data: { order: orderMsg.join(', ') },
5959
fix (fixer) {
60-
const source = sourceCode.getText();
61-
const last = properties[properties.length - 1];
62-
// end loc to replace(including whitespaces).
63-
const finalEnd = sourceCode.getTokenAfter(last, token => token.value === '}' && token.type === 'Punctuator').range[0];
6460
// reorder the properties and put in result array.
6561
const result = [];
6662
for (let j = 0; j < keyNames.length; j++) {
6763
const insertedIndex = orderMsg.indexOf(keyNames[j]);
6864
const propertyCode = sourceCode.getText(properties[j]);
69-
const propertyStart = properties[j].range[1];
70-
const propertyEnd = j < properties.length - 1 ? properties[j + 1].range[0] : finalEnd;
71-
let trailing = source.slice(propertyStart, propertyEnd);
72-
73-
// for last property, should check & add trailling commas.
74-
if (j === properties.length - 1 && sourceCode.getTokenAfter(last).value !== ',') {
75-
trailing = ', ' + trailing;
76-
}
77-
result[insertedIndex] = propertyCode + trailing;
65+
result[insertedIndex] = propertyCode;
7866
}
7967

80-
const start = properties[0].range[0];
81-
82-
return fixer.replaceTextRange(
83-
[start, finalEnd],
84-
result.join('')
85-
);
68+
return orderMsg.map((key, index) => {
69+
const propertyToInsert = test.properties[keyNames.indexOf(key)];
70+
return fixer.replaceText(test.properties[index], sourceCode.getText(propertyToInsert));
71+
});
8672
},
8773
});
8874
}

0 commit comments

Comments
 (0)