From f1ae6edc4092f58ee8ba46c6cefc19fa316fbffb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 3 Jul 2024 23:13:31 -0500 Subject: [PATCH] [Refactor] `sort-comp`: use Object.entries instead of for-in --- lib/rules/sort-comp.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index cf24961629..e35574a682 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -124,6 +124,7 @@ module.exports = { }, create: Components.detect((context, components) => { + /** @satisfies {Record} */ const errors = {}; const methodsOrder = getMethodsOrder(context.options[0]); @@ -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]; } } - } + }); } /**