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).
Justify or complete an enum/whitelist that covers an open domain
When enumerating a subset of an open-ended domain, either cover the realistic set or document why only those values are allowed.
Bad example
| 1 | // Why these four and not EUR, GBP, ...? No rationale, breaks for the next currency. |
| 2 | export enum Currency { |
| 3 | NOK = 'NOK', |
| 4 | SEK = 'SEK', |
| 5 | DKK = 'DKK', |
| 6 | USD = 'USD', |
| 7 | } |
Explanation (EN)
An arbitrary subset of a larger domain will fail for the first legitimate value left out, and reviewers cannot tell whether the omission was intentional.
Objašnjenje (HR)
Proizvoljan podskup vece domene zakazat ce za prvu legitimnu vrijednost koja je izostavljena, a recenzenti ne mogu znati je li izostavljanje bilo namjerno.
Good example
| 1 | // Cover the realistic supported set, or document the constraint explicitly. |
| 2 | // Supported because exchange-rate data is only available for these markets. |
| 3 | export enum Currency { |
| 4 | NOK = 'NOK', |
| 5 | SEK = 'SEK', |
| 6 | DKK = 'DKK', |
| 7 | USD = 'USD', |
| 8 | EUR = 'EUR', |
| 9 | GBP = 'GBP', |
| 10 | } |
Explanation (EN)
Either covering the realistic set or stating the constraint removes ambiguity and prevents avoidable gaps.
Objašnjenje (HR)
Bilo pokrivanje realnog skupa ili navođenje ogranicenja uklanja dvosmislenost i sprjecava izbjezive praznine.