Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: javascript
simplificationearly-returnreadability
Return boolean directly instead of a mutable flag
When a loop sets a flag then returns it, return early/directly; if the flag's only false-setting line is the initializer, simplify it away.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | let isAffiliate = false; |
| 2 | matchStrings.forEach(s => { if (url.includes(s)) isAffiliate = true; }); |
| 3 | return isAffiliate; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | return matchStrings.some(s => url.includes(s)); |
Explanation (EN)
Objašnjenje (HR)