-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Nonsense warnings about using next
to skip iteration
#1238
Comments
I realize this cop can be disabled (and I've done so). However, considering the questionable warnings it produces I don't think it's wise to enable this by default (at least not in its current state). |
That's a thorough ticket. :-) Both this cop and the
Yes, I agree. This has been in my todo list for a while now. If I don't find time to refine those cops I'll disable them by default. @yujinakayama @jonas054 You input is most welcome! |
@bbatsov Your plan sounds good to me! I agree with @yorickpeterse that the changes suggested by these cops aren't always improvements. Sometimes a simple |
The |
@yorickpeterse @bbatsov @jonas054 I agree. Though I usually tend to prefer To refine the cops, I think we need to make a list of example code (though there're already some in the specs) and figure out what preferences there are. By default, the refined cops should register offenses only for definitely bad structure that almost all people would agree (this would be less strict than the current), and add some configuration options to fit each preference. |
@geniou I'm starting to forget things we've already done. Yes, doing the same for In the long run, however, we should do something similar to what @yujinakayama suggested - making those two cops more configurable to suit more personal preferences. |
I'll try to add the mentioned configuration to the next cop. Should we then increase the default value for both cops by default? What would be good, 3? |
@geniou I've already added the config option, but I've yet to decide on its default. I'm still thinking whether to only update the default or to disable the cop by default. |
Since the next cop is from me I would love that it stays enabled. ;-) Do we have use cases where we agree that we need to adapt the cop? |
Of course - you can disable it just like any other cop in |
See discussion at rubocop/rubocop#1238
Consider the following snippet of Ruby code:
When running Rubocop on this file the output is as following:
The second warning makes sense but the first one is absolute nonsense. That is, the following code is no better:
To make things more confusing, the following doesn't produce the above warning:
As a more real-world example, there's the following snippet of code that we have:
Rewriting this as following brings absolutely no benefits:
It might save you a single level of indentation but that's about it. It might make sense if you have multiple conditionals that determine whether or not to skip the loop. However, in simple cases such as those shown above the warning is utter nonsense.
Another snippet, which also contains a confusing line about where the error occurs:
This result in:
Again rewriting this gives no benefits, unless more complex code were to be used as the conditional:
I realize that it's rather difficult to figure out the complexity of code following a
next
and when to throw warnings or not, but throwing this warning always is a massive overkill.The text was updated successfully, but these errors were encountered: