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).
Resolve aliased upstream fields once with an explicit fallback
When an external source exposes the same value under multiple field names, normalize it in one accessor with a defined fallback order.
Bad example
| 1 | // scattered across call sites |
| 2 | const a = tag.instrumentId; |
| 3 | // ...elsewhere... |
| 4 | const b = otherTag.milistreamId; // same logical value, different name |
| 5 | // callers must each remember both spellings |
Explanation (EN)
Spreading knowledge of both field names across call sites means any site that checks only one spelling silently returns undefined for the other, and the fallback rule is duplicated and easy to get inconsistent.
Objašnjenje (HR)
Sirenje znanja o oba imena polja po pozivnim mjestima znaci da svako mjesto koje provjerava samo jedno ime tiho vraca undefined za drugo, a pravilo zamjene se duplicira i lako postaje nedosljedno.
Good example
| 1 | public get instrumentId(): string | undefined { |
| 2 | const tag = this.meta.tags?.find((t) => t.tagTypeName === 'Instrument'); |
| 3 | // Upstream emits instrumentId or milistreamId; both carry the same insref. |
| 4 | return tag?.instrumentId ?? tag?.milistreamId; |
| 5 | } |
Explanation (EN)
A single accessor encapsulates the alias knowledge with an explicit precedence (?? prefers the primary name), so every caller gets a consistent value and the fallback lives in one documented place.
Objašnjenje (HR)
Jedan pristupnik enkapsulira znanje o aliasima s eksplicitnim prioritetom (?? preferira primarno ime), pa svaki pozivatelj dobiva dosljednu vrijednost, a zamjena zivi na jednom dokumentiranom mjestu.
Notes (EN)
Add a short comment naming the upstream quirk and a test for each branch (primary present, only alias present, both present prefers primary).
Bilješke (HR)
Dodaj kratak komentar koji imenuje osobitost izvora i test za svaku granu (primarno postoji, samo alias postoji, oba postoje pa se preferira primarno).