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).
Extract one validity predicate when the same rule applies to two input paths
When a calendar/picker enforces the same validity rules through two separate entry points (click vs typed text), centralize the check into a single function reused by both — divergence between paths causes inconsistent UI behavior.
Bad example
| 1 | // Calendar click path |
| 2 | const isDateDisabled = isBeforeMinDate || isDisabledByAvailability; |
| 3 | // Text field path (useDateField) has no equivalent check at all |
Explanation (EN)
The calendar visually disables invalid dates, but typing the same date into the text field bypasses the check entirely and gets accepted, so the two input paths disagree about what's valid.
Objašnjenje (HR)
Kalendar vizualno onemogucuje nevaljane datume, ali upisivanje istog datuma u tekstualno polje potpuno zaobilazi provjeru i biva prihvaceno, pa se dvije putanje unosa ne slazu oko toga sto je valjano.
Good example
| 1 | const isDateSelectable = (date: Date) => |
| 2 | !isBeforeMinDate(date) && !isDisabledByAvailability(date); |
| 3 | // used by both the calendar click handler and the text field's onChange |
Explanation (EN)
A single predicate function used by both the calendar and the text field guarantees they can never silently drift apart on what counts as a valid date.
Objašnjenje (HR)
Jedna funkcija predikata koju koriste i kalendar i tekstualno polje jamci da nikad ne mogu tiho odstupiti u tome sto se racuna kao valjan datum.