Closed
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
- Why should this rule be added?
This rule should flag conditions that are used multiple times in the same branching statement like if-else-if or switch statement.
- Provide several examples of what would and wouldn't trigger violations.
Violating Examples
if x < 5 {
foo()
} else if x < 2 {
bar()
} else if x < 5 { // duplicated condition
baz()
}
switch x {
case "a":
foo()
case "a" // duplicated condition
bar()
}
Non-Violating Examples
if x < 5 {
foo()
baz()
} else if x < 2 {
bar()
}
switch x {
case "a":
foo()
bar()
}
- Should the rule be configurable, if so what parameters should be configurable?
This rule doesn’t need to be configurable.
- Should the rule be opt-in or enabled by default? Why?
See README.md for guidelines on when to mark a rule as opt-in.
This would be a good candidate for a builtin rule as it points out bad structured code.