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 ruleP1universalStack: typescript
correctnesscontrol-flowedge-cases
Guard a conditional on the actual input that justifies it
Add the precondition that makes a branch valid (e.g. only filter-out logic runs when an excludeId was supplied) so the branch isn't entered spuriously.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | if (collection.articles.length !== withoutCurrent.length) { |
| 2 | totalCount -= 1; // runs even when no excludeId was requested |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (queryParam.excludeId && collection.articles.length !== withoutCurrent.length) { |
| 2 | totalCount -= 1; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)