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).
Update merge/copy paths whenever you add a new field
A field-by-field merge function must be updated whenever the entity gains a new column.
Bad example
| 1 | function mergeExternalIdentities(dest: Identities, src: Identities): Identities { |
| 2 | return { |
| 3 | bellsheepId: dest.bellsheepId ?? src.bellsheepId, |
| 4 | purehelpId: dest.purehelpId ?? src.purehelpId, |
| 5 | // drpAuthorId was added to the schema but never added here |
| 6 | }; |
| 7 | } |
Explanation (EN)
The function was written before the new column existed and nobody updated it when the column was added, so merging two records silently loses the new field's value from the surviving record.
Objašnjenje (HR)
Funkcija je napisana prije nego što je novi stupac postojao i nitko je nije ažurirao kad je stupac dodan, pa spajanje dva zapisa tiho gubi vrijednost novog polja s preživjelog zapisa.
Good example
| 1 | function mergeExternalIdentities(dest: Identities, src: Identities): Identities { |
| 2 | return { |
| 3 | bellsheepId: dest.bellsheepId ?? src.bellsheepId, |
| 4 | purehelpId: dest.purehelpId ?? src.purehelpId, |
| 5 | drpAuthorId: dest.drpAuthorId ?? src.drpAuthorId, |
| 6 | }; |
| 7 | } |
Explanation (EN)
When a schema gains a new field, grep for every function that enumerates that entity's other fields (merge, copy, clone, diff) and add the new one in the same change, plus a test that exercises the merge with that field set.
Objašnjenje (HR)
Kad shema dobije novo polje, pretraži (grep) sve funkcije koje nabrajaju ostala polja tog entiteta (merge, copy, clone, diff) i dodaj novo polje u istoj izmjeni, uz test koji provjerava merge s tim postavljenim poljem.