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).
Name ambiguous multi-id decisions explicitly in preview output
A dry-run/preview tool must spell out the case where an entity gains an additional linked id.
Bad example
| 1 | const claimed = await findByExternalId(externalId); |
| 2 | if (claimed) return { kind: "already" }; |
| 3 | // otherwise falls through to name-matching, which may link for the wrong |
| 4 | // reason or create a duplicate for a person already linked under another id |
Explanation (EN)
Once an entity can hold more than one external id, a plain "already claimed" check by that single id misses the case where the same entity is already known under a different id — the code falls into a branch that wasn't designed for it.
Objašnjenje (HR)
Kad entitet može imati više od jednog vanjskog id-a, obična provjera 'već zauzeto' po tom jednom id-u propušta slučaj kad je isti entitet već poznat pod drugim id-em — kod upada u granu koja za to nije bila predviđena.
Good example
| 1 | const owner = await findPersonOwningAnyExternalId(person, externalId); |
| 2 | if (owner?.matchedByOtherId) { |
| 3 | console.log(`author ${externalId} -> added to person ${owner.id} (already has ${owner.matchedByOtherId})`); |
| 4 | return { kind: "addedSecondId", personId: owner.id }; |
| 5 | } |
Explanation (EN)
Give this outcome its own explicit case, and print it in the dry-run output, so an editor reviewing the preview sees exactly which people are gaining a second linked id before anything is written.
Objašnjenje (HR)
Daj ovom ishodu vlastiti eksplicitni slučaj i ispiši ga u dry-run izlazu, tako da urednik koji pregledava pregled vidi točno kojima osobama se dodaje drugi povezani id prije nego što se bilo što zapiše.