Rule Request: force_exhaustive_switch
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request force_exhaustive_switch
Enable to force exhaustive switch unless bypassed.
There's an ancient issue about this which stated exhaustive switch was very helpful. It is so useful that in our case, we would like to make it mandatory by not allowing default: clause.
No configuration is needed. And it should be disabled by default as no one was requesting it before, so there must be not enough people who really want it, as it's more like a choice of style.
However, in our case it's more than that. We use Swiftlint to fail our CI and want it to be configured it in a way that unless developer explicitly bypass this rule, we will fail CI and force developers to use exhaustive switch. This is especially useful for things like managing server configuration etc. so that when something new is added, it's hard to miss something. So:
- Should the rule be configurable, if so what parameters should be configurable? - NO
- Should the rule be opt-in or enabled by default? Why? - NO
What would trigger
switch myEnum {
case .case1: ()
default: ()
}
See README.md for guidelines on when to mark a rule as opt-in.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with README.md's opt-in-rules guidance and inspect how existing opt-in rules are structured. Use the switch example in this issue to determine the expected diagnostic, including the bypass behavior; done means switches with a default clause are reported unless explicitly bypassed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100