Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Coerce with toString and type the param, instead of any
Validate and explicitly convert the supported input domain; do not claim a string annotation changes runtime values.
Bad example
| 1 | function slugify(name: any) { return name.toLowerCase(); } |
Explanation (EN)
any permits a non-string to reach a string method unchecked.
Objašnjenje (HR)
Good example
| 1 | function slugify(name: string) { return name.toLowerCase(); } |
| 2 | function slugFromInput(value: unknown) { |
| 3 | if (typeof value !== "string") throw new TypeError("Expected a name"); |
| 4 | return slugify(value); |
| 5 | } |
Explanation (EN)
Only an actual string reaches the string helper; add intentional numeric conversion only if the domain accepts it.
Objašnjenje (HR)
Notes (EN)
Accept the actual input domain and validate or convert it at the boundary before calling a string-only helper.
Exceptions / Tradeoffs (EN)
toString throws on null/undefined and can invoke custom object behavior. String(value) also accepts values such as null that may be invalid domain data; conversion is not validation.