Skip to content

Commit f05bd18

Browse files
committed
[Refactor] sort-comp: use a normal for loop on an array instead of for-in
1 parent 5e9edf8 commit f05bd18

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/rules/sort-comp.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ module.exports = {
124124
},
125125

126126
create: Components.detect((context, components) => {
127+
/** @satisfies {{ node: ASTNode, score: number, closest: { distance: number, ref: { node: null | ASTNode, index: number } } }[]} */
127128
const errors = {};
128129
const methodsOrder = getMethodsOrder(context.options[0]);
129130

@@ -287,15 +288,13 @@ module.exports = {
287288
* Dedupe errors, only keep the ones with the highest score and delete the others
288289
*/
289290
function dedupeErrors() {
290-
for (const i in errors) {
291-
if (has(errors, i)) {
292-
const index = errors[i].closest.ref.index;
293-
if (errors[index]) {
294-
if (errors[i].score > errors[index].score) {
295-
delete errors[index];
296-
} else {
297-
delete errors[i];
298-
}
291+
for (let i = 0; i < errors.length; i += 1) {
292+
const index = errors[i].closest.ref.index;
293+
if (errors[index]) {
294+
if (errors[i].score > errors[index].score) {
295+
delete errors[index];
296+
} else {
297+
delete errors[i];
299298
}
300299
}
301300
}

0 commit comments

Comments
 (0)