Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Enforce types in the signature, don't rely on callers' good will
Validate boundary values before using precise internal types; assertions do not make callers trustworthy.
Bad example
| 1 | const { replyId } = req.query; // typed string | string[] |
| 2 | // 'we always send a string so casting is fine' |
| 3 | Service.adminDeleteReply(Number(replyId), ...); |
Explanation (EN)
A repeated or malformed query value can reach numeric conversion unchecked.
Objašnjenje (HR)
Good example
| 1 | const rawId = req.query.replyId; |
| 2 | const replyId = parseValidReplyId(rawId); |
| 3 | await Service.adminDeleteReply(replyId); |
Explanation (EN)
The parser handles missing/repeated/malformed values and range requirements before the service receives a valid ID.
Objašnjenje (HR)
Notes (EN)
Accept unknown or the real framework union at an untyped boundary, validate shape and domain, then call an internal function with a precise type.
Exceptions / Tradeoffs (EN)
TypeScript annotations and as assertions do not validate query strings, JSON or runtime callers. Avoid repeated validation inside a trusted already-validated internal path.