Skip to content

Commit f1ae6ed

Browse files
committed
[Refactor] sort-comp: use Object.entries instead of for-in
1 parent bcb987a commit f1ae6ed

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/rules/sort-comp.js

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

126126
create: Components.detect((context, components) => {
127+
/** @satisfies {Record<string, { 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,18 +288,19 @@ 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+
entries(errors).forEach((entry) => {
292+
const i = entry[0];
293+
const error = entry[1];
294+
295+
const index = error.closest.ref.index;
296+
if (errors[index]) {
297+
if (error.score > errors[index].score) {
298+
delete errors[index];
299+
} else {
300+
delete errors[i];
299301
}
300302
}
301-
}
303+
});
302304
}
303305

304306
/**

0 commit comments

Comments
 (0)