Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Drop runtime checks that the variable's declared type rules out
Remove checks only when the precise validated domain makes them impossible; non-nullable is not the same as truthy.
Bad example
| 1 | function label(value: string) { |
| 2 | if (typeof value !== "string") return ""; |
| 3 | return value.trim(); |
| 4 | } |
Explanation (EN)
A presence check may be redundant for a validated object, but non-nullable fields can still contain valid or invalid falsy values.
Objašnjenje (HR)
Good example
| 1 | function label(value: string) { |
| 2 | return value.trim(); |
| 3 | } |
Explanation (EN)
This internal helper assumes a validated string boundary; it still accepts an empty string and does not remove any nonempty validation.
Objašnjenje (HR)
Notes (EN)
Remove only checks actually excluded by the trusted value domain, after verifying all producers and the checked predicate.
Exceptions / Tradeoffs (EN)
string includes empty string and number includes zero/NaN, so a truthiness guard is not redundant merely because a field is non-nullable. Untyped boundaries still need validation.