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).
frontend ruleP2universalStack: javascript
control-flowguard-clausecorrectness
Return early in a guard branch instead of falling through to a reset
When a condition short-circuits the work, return inside that branch so trailing reset logic (e.g. setting a flag false) doesn't run unintentionally.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | useUpdateEffect(() => { |
| 2 | if (!isFilterChanged) { |
| 3 | setThreads([]); |
| 4 | fetchData(pageNumber); |
| 5 | } |
| 6 | setIsFilterChanged(false); // runs even when isFilterChanged was true |
| 7 | }, [pageNumber]); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | useUpdateEffect(() => { |
| 2 | if (isFilterChanged) { |
| 3 | setIsFilterChanged(false); |
| 4 | return; |
| 5 | } |
| 6 | setThreads([]); |
| 7 | fetchData(pageNumber); |
| 8 | }, [pageNumber]); |
Explanation (EN)
Objašnjenje (HR)