Skip to content

Commit

Permalink
[Refactor] sort-comp: use Object.entries instead of for-in
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 4, 2024
1 parent bcb987a commit f1ae6ed
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ module.exports = {
},

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

Expand Down Expand Up @@ -287,18 +288,19 @@ module.exports = {
* Dedupe errors, only keep the ones with the highest score and delete the others
*/
function dedupeErrors() {
for (const i in errors) {
if (has(errors, i)) {
const index = errors[i].closest.ref.index;
if (errors[index]) {
if (errors[i].score > errors[index].score) {
delete errors[index];
} else {
delete errors[i];
}
entries(errors).forEach((entry) => {
const i = entry[0];
const error = entry[1];

const index = error.closest.ref.index;
if (errors[index]) {
if (error.score > errors[index].score) {
delete errors[index];
} else {
delete errors[i];
}
}
}
});
}

/**
Expand Down

0 comments on commit f1ae6ed

Please sign in to comment.