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: typescript
domreadabilitytesting
Use document.head/document.body instead of querying singleton elements
The document object exposes head and body directly and always defined; querySelector('head') plus a null guard is redundant noise.
PR: FCK-3307 Improve the order of <head> elementsCreated: Jul 16, 2026
Bad example
Old codets
| 1 | const head = document.querySelector('head'); |
| 2 | if (!head) throw new Error('No <head> found'); |
Explanation (EN)
querySelector returns a nullable result, forcing a pointless guard for an element the parser guarantees exists.
Objašnjenje (HR)
querySelector vraća nullable rezultat i tjera na besmislen guard za element koji po parseru uvijek postoji.
Good example
New codets
| 1 | const head = document.head; |
Explanation (EN)
document.head is typed non-null and reads exactly like what it is.
Objašnjenje (HR)
document.head je tipiziran kao non-null i čita se točno kao ono što jest.