Skip to content

Commit 41323da

Browse files
kzhrkFloEdelmann
andauthored
refactor(define-macros-order): simplify beforeMacro detection logic
Use array.find() instead of a for loop with break statement for a more idiomatic and readable approach to finding the macro name. Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent 66d24c3 commit 41323da

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/rules/define-macros-order.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,9 @@ function create(context) {
221221
*/
222222
function reportNotOnTop(macro, nodes, before) {
223223
// Determine if 'before' is a macro from the order list
224-
let beforeMacro = null
225-
for (const macroName of order) {
226-
const macroNodes = macrosNodes.get(macroName) ?? []
227-
if (macroNodes.includes(before)) {
228-
beforeMacro = macroName
229-
break
230-
}
231-
}
224+
const beforeMacro = order.find((macroName) =>
225+
(macrosNodes.get(macroName) ?? []).includes(before)
226+
)
232227

233228
// Decide which message to use
234229
const messageId = beforeMacro ? 'macrosUnordered' : 'macrosNotAtTop'

0 commit comments

Comments
 (0)