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).
fullstack ruleP1universalStack: typescript
authorizationmodelingstatecorrectness
Model overlapping roles as separate flags, not one mutually-exclusive level
When a higher role implies a lower one (admin is also registered), branching with else-if on a single access level hides the overlap; track independent flags (isAdmin, isRegistered) so checks for the base role still pass.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | if (isAdmin) { |
| 2 | level = UserAccessLevel.Admin; |
| 3 | } else if (isRegistered) { |
| 4 | level = UserAccessLevel.Registered; |
| 5 | } |
| 6 | // later: rendering for registered users misses admins |
| 7 | if (level === UserAccessLevel.Registered) { /* admin won't match */ } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const isRegistered = registered || admin; // admin implies registered |
| 2 | const isAdmin = admin; |
| 3 | // checks for the base role include the higher role |
| 4 | if (isRegistered) { /* matches both registered and admin */ } |
Explanation (EN)
Objašnjenje (HR)