Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Aggregate per-item logging inside fan-out loops instead of logging each iteration
A log call inside a broadcast or fan-out loop costs an argument object per item even when the level is disabled, and when it is enabled it multiplies log volume by the number of recipients.
Bad example
| 1 | for (const client of clients) { |
| 2 | if (!client.topics.has(topic)) { |
| 3 | emitDebug("skipping client", { id: client.id, topic }); // per client, per message |
| 4 | continue; |
| 5 | } |
| 6 | client.write(payload); |
| 7 | } |
Explanation (EN)
The object literal is built for every skipped client on every message even at info level, and enabling debug floods the aggregator with one line per recipient.
Objašnjenje (HR)
Objektni literal gradi se za svakog preskocenog klijenta i za svaku poruku cak i na info razini, a ukljucivanje debug razine preplavi agregator s jednom linijom po primatelju.
Good example
| 1 | let skipped = 0; |
| 2 | for (const client of clients) { |
| 3 | if (!client.topics.has(topic)) { |
| 4 | skipped += 1; |
| 5 | continue; |
| 6 | } |
| 7 | client.write(payload); |
| 8 | } |
| 9 | emitInfo("broadcast", { topic, delivered: clients.length - skipped, skipped }); |
Explanation (EN)
One line per broadcast carries the same information as a counter, with no per-item allocation and no volume that scales with recipients.
Objašnjenje (HR)
Jedna linija po emitiranju nosi istu informaciju kao brojac, bez alokacije po stavci i bez volumena koji raste s brojem primatelja.
Notes (EN)
If you genuinely need per-item detail, guard the call with an explicit level check so the arguments are never constructed when the level is off.
Bilješke (HR)
Ako ti stvarno treba detalj po stavci, zastiti poziv izricitom provjerom razine kako se argumenti nikad ne bi gradili kad je razina iskljucena.