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 ruleP1universalStack: TypeScript / React
dryabstractionssrencapsulation
Encapsulate environment and window checks inside the resolver function
Don't make every caller perform the same defensive window/global checks before calling a helper; push those checks into the helper so callers stay clean and logic isn't duplicated.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const product = resolveArticleProduct(typeof window !== 'undefined' ? window.product : undefined); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // resolveArticleProduct internally does the typeof window / window.product check |
| 2 | const product = resolveArticleProduct(); |
Explanation (EN)
Objašnjenje (HR)