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
statecorrectnessinitializationordering
Set a derived validity flag before the code path that reads it
A flag initialized true and only flipped false by getters invoked later is read stale; compute validity (e.g. via setters in the constructor) before it's consumed.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | let isDataValid = true; |
| 2 | if (!isDataValid) fetchLayer2(); // getters that set false run after this |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // validity computed in constructor via setters before this read |
| 2 | if (!this.isDataValid) fetchLayer2(); |
Explanation (EN)
Objašnjenje (HR)