Skip to content

Commit

Permalink
[Refactor] sort-comp: use a normal for loop on an array instead of …
Browse files Browse the repository at this point in the history
…for-in
  • Loading branch information
ljharb committed Jul 4, 2024
1 parent 5e9edf8 commit f05bd18
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 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 {{ 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,15 +288,13 @@ 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];
}
for (let i = 0; i < errors.length; i += 1) {
const index = errors[i].closest.ref.index;
if (errors[index]) {
if (errors[i].score > errors[index].score) {
delete errors[index];
} else {
delete errors[i];
}
}
}
Expand Down

0 comments on commit f05bd18

Please sign in to comment.