Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: javascript
readabilitycontrol-flowclean-code
Choose clear guards for short void handlers
Choose a readable guard shape for void functions; use early returns when they simplify the actual control flow.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | function onBlur(element) { |
| 2 | if (element && element.tagName === 'INPUT') return; |
| 3 | if (this.input) this.input.blur(); |
| 4 | } |
Explanation (EN)
A negative guard can obscure one simple positive action in an otherwise short handler.
Objašnjenje (HR)
Good example
New codejavascript
| 1 | function onBlur(element) { |
| 2 | const canBlur = !element || element.tagName !== 'INPUT'; |
| 3 | if (this.input && canBlur) this.input.blur(); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Choose a positive condition for a short single action when it makes the predicate easier to read, preserving subsequent work and side-effect order.
Exceptions / Tradeoffs (EN)
Early returns are valid in void functions and often reduce nesting. This is a local readability choice, not a prohibition.