-
Notifications
You must be signed in to change notification settings - Fork 214
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
Lint/DuplicateBranch: Duplicate branch body detected -- for code it previously was happy with #227
Comments
Discussion on rubocop's new Lint/DuplicateBranch quirks is at rubocop/rubocop#8404 |
I think the idea behind this is that |
So it's expecting this:
|
@jmkoni ahh thanks a lot for spotting that. Obviously I stared too much at the |
@drnic no worries :) happy to help! |
This cop just started hollering for us. I think this is a step back for a pretty common usage of case statements w/ enums. Here is an example from a code base I work in everyday:
In our domain the four types of facility sizes are a well know attribute on our Facility model. So when getting something like this So while the refactoring Rubocop is proposing is more DRY in the technical sense, the logic here is not duplicated. Refactoring to handle the While I can see cases where you may want this cop enabled, I think this an overly strict definition of correctness that isn't in the spirit of standardrb. This is also way more than I've written about a single lint rule, so maybe I should just figure out how to turn off the rule for our project and move on 😏 . But I think this should be off for the default looser world of standardrb - what say y'all? |
Proposal: PR to disable this rule: #228 |
Hey @drnic, hey @rsanheim! Thanks for raising these issues. When @jmkoni & I were discussing this rule, this kind of risk of limiting the expressiveness of code (if two semantically unrelated branches happen to resolve to the same value, it's not always ideal to smoosh them together), but turned the rule on anyway. We turned it on as a bit of a trial balloon and you have successfully popped it. Thank you! |
I'm getting this warning on the following code and the logic is quite correct in implementation and does not lend itself to be refactored based on your rule W: Lint/DuplicateBranch: Duplicate branch body detected.
|
@klueless-io we've disabled this rule from Standard. You might want to make sure you've upgraded to latest and try again. Separately, if you can reproduce what you're seeing with a default rubocop config, I'm sure they'd appreciate the bug report |
I upgraded to standard 0.10/rails 6.1.0.rc2, running ruby 2.7.1:
And now the following method is receiving a warning that doesn't seem correct:
The warning points to the
else
in thecase
statement above:This new warning is in 0.10.0 and 0.10.1, but not 0.9.0
The text was updated successfully, but these errors were encountered: