Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Switch enums exhaustively instead of a catch-all default
Enforce exhaustive handling using the language/compiler contract; no default alone is not a universal guarantee.
Bad example
| 1 | switch state { case .loading: a(); default: b() } |
Explanation (EN)
A catch-all can silently route newly added variants through an unrelated behavior.
Objašnjenje (HR)
Good example
| 1 | switch state { case .loading: a(); case .loaded: b(); case .failed: c() } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Use the language's actual exhaustiveness mechanism for a closed enum/union, and make new variants fail the relevant compiler or lint check.
Exceptions / Tradeoffs (EN)
Swift and TypeScript differ: omitting default alone does not guarantee a TypeScript compile error. A never assertion in default can enforce exhaustiveness; non-frozen external Swift enums may need @unknown default.