Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Preserve empty-string-as-absent when replacing a truthiness check
When refactoring a truthiness guard (`value ?` / `if (value)`) into a more explicit condition, keep a truthiness check (`!!value` / `value && ...`) rather than switching to `value != null` / `!== undefined`. Otherwise an empty string passes as 'present' and leaks through as an empty src/href/label.
Bad example
| 1 | const hasImage = avatarUrl != null && !avatarUrl.startsWith('{{'); |
| 2 | // avatarUrl === '' passes -> <img src=""> (broken) |
Explanation (EN)
!= null treats an empty string as a real value, reintroducing a broken/empty render that the original truthiness check avoided.
Objašnjenje (HR)
Good example
| 1 | const hasImage = avatarUrl && !avatarUrl.startsWith('{{'); |
| 2 | // '' is correctly treated as no image |
Explanation (EN)
Truthiness keeps '' in the 'absent' bucket, matching the original `avatarUrl ?` check.
Objašnjenje (HR)
Notes (EN)
Watch for this whenever you 'tighten' a guard: `!= null` / `??` semantics differ from truthiness for '', 0, and false.