-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fallthrough false positive #1892
Comments
I'm not sure I'd consider this a false positive. You could avoid the |
Yeah, I know I can use a workaround with closure/function or disabling a rule. I can also make a several cases to remove the default case, but this removes code simplicity and readability IMO. |
I disagree: removing the I still think the rule is behaving accordingly here. We could probably add a configuration for not warning when the next case is a |
Exhaustive switch requirement is a very helpful feature, but very context-dependent IMHO. It's not always bad to have a default case, else apple wouldn't make it I think. A configuration seems good alternative to me. |
Instead of a configuration for not warning when the next case is a
|
100% agree, that's a very sensible remark! This is the way that this rule should work, without any configuration |
+1 This rule is nice to detect combinable let integerToDescribe = 5
var description = "The number \(integerToDescribe) is"
switch integerToDescribe {
case 2, 3, 5, 7, 11, 13, 17, 19:
description += " a prime number, and also"
fallthrough
default:
description += " an integer."
}
print(description)
// Prints "The number 5 is a prime number, and also an integer." The original Rule Request (#1834) suggested this rule as opt-in. Maybe this would be a better fit because currently it triggers for scenarios where |
I agree with @weichsel. |
New Issue Checklist
Bug Report
According to rule request, the primary goal of marking fallthrough statement is that it can be replaced by combining cases. In most cases.
However there are cases where that's not possible, reasonable or leading to code duplication:
The mentioned linkedin styleguide also mentioned
whenever possible
, but not saying anything on avoidance.Take a look at the sample below. I have a block of code that should run in any other cases rather than
.needsRequest
plus a small addition for.denied
case.To resolve the warning, I am forced to copy-paste the default section which is error prone (+ possibly may lead to function_body_length violation).
I think the rule should ignore falling through to default case. It's not that hard to read and a default case already marks the common code for a several case statements.
Environment
Swiftlint 0.23.0, installed through CocoaPods
no
xcode-select -p
)?xcode 9
echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
to quickly test if your example is really demonstrating the issue. If your example is more
complex, you can use
swiftlint lint --path [file here] --no-cache --enable-all-rules
.The text was updated successfully, but these errors were encountered: