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).
backend ruleP2universalStack: javascript
control-flowearly-returnreadabilityguard-clause
Invert guard clauses to return early and reduce nesting
Return early on the failure condition instead of wrapping the happy path in a large if block, to keep indentation flat.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | if (userData) { |
| 2 | // many lines of logic |
| 3 | } else { |
| 4 | return res.status(500).end(); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (!userData) return res.status(500).end(); |
| 2 | // many lines of logic |
Explanation (EN)
Objašnjenje (HR)