Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Trim string inputs and reject blank values with the right validators
Combine a trimming transformer with a not-empty validator so whitespace-only inputs are rejected and stored trimmed, instead of a min-length check that still accepts padded blanks.
Bad example
| 1 | @MinLength(1) // " " passes and is stored with spaces |
| 2 | public name!: string; |
Explanation (EN)
A minimum length check alone accepts a whitespace-only name.
Objašnjenje (HR)
Good example
| 1 | function parseName(value: unknown): string { |
| 2 | if (typeof value !== "string") throw new TypeError("Expected a name"); |
| 3 | const name = value.trim(); |
| 4 | if (!name) throw new Error("Name is required"); |
| 5 | return name; |
| 6 | } |
Explanation (EN)
This field-specific parser checks shape before trimming and rejects a normalized blank name.
Objašnjenje (HR)
Notes (EN)
Normalize whitespace before nonempty validation when leading/trailing spaces are insignificant to the field, and verify transform order and input type.
Exceptions / Tradeoffs (EN)
Passwords, signatures and whitespace-significant text must not be trimmed blindly. @Trim is not universally built into every validator; use the actual configured transformer.