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).
Let web-component boolean attributes be explicitly set to false
When validating a web component's attribute values, don't treat the literal string 'false' as an invalid/absent value — that makes it impossible to explicitly opt out if the attribute's default behavior ever flips.
Bad example
| 1 | const isValidAttributeValue = (value: unknown): boolean => |
| 2 | value != null && value !== '' && value !== false; |
Explanation (EN)
Rejecting `false` as invalid means the only way to represent 'off' is by omitting the attribute. If the default for an omitted attribute ever becomes `true`, there's no way left to explicitly pass `false`.
Objašnjenje (HR)
Odbijanje `false` kao nevaljanog znaci da je jedini nacin predstavljanja 'iskljuceno' izostavljanje atributa. Ako default za izostavljeni atribut ikad postane `true`, vise nema nacina da se eksplicitno proslijedi `false`.
Good example
| 1 | const isValidAttributeValue = (value: unknown): boolean => |
| 2 | value != null && value !== ''; |
Explanation (EN)
Accept explicit `false` as a valid value distinct from 'attribute absent', keeping the door open for the default to change later without breaking consumers who need to opt out.
Objašnjenje (HR)
Prihvati eksplicitni `false` kao valjanu vrijednost razlicitu od 'atribut odsutan', ostavljajuci otvorena vrata da se default kasnije promijeni bez lomljenja onih koji trebaju eksplicitno iskljuciti.