-
-
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
Performance::RedundantMerge dislikes implicit self
#3430
Comments
After looking at this a bit, I'm not sure what the best fix for this is. We could make it so that when rubocop encounters a Or, perhaps it's just bad practice to call |
…when receiver is implicit This cop would blow up when inspecting code that involved sending `#merge!` to `self` implicitly, e.g.: ``` class Foo def bar(baz) merge!(baz) end end ``` This change fixes that.
Maybe I'm misunderstanding, but in the fix in eb54e93, it looks like instead of making sure I don't mean to disparage, because I don't have an alternative solution, but this does not seem ideal if I'm understanding it correctly. |
@supremebeing7: I was on the fence for quite a while about this. I haven't seen the construct in production code, so I had to make a judgement call on whether it is more likely that someone is inheriting from Since you probably have more experience with this kind of code than I do, would you say that we should treat it the same as a |
@Drenmi I definitely understand. This is a bit of a weird edge case. This is the first time I've seen code like this in production, and I didn't write it, so I'm unfortunately not terribly familiar with it either 😟 Looking more closely at my codebase, this is the root of the issue:
So, it's a little odd maybe, but I don't know that rubocop should make a judgment on its oddness (not until there's a cop for that, anyway 😄 ). I think the goal of the What do you think? Does that make sense, or is it getting too complicated? |
…when receiver is implicit This cop would blow up when inspecting code that involved sending `#merge!` to `self` implicitly, e.g.: ``` class Foo def bar(baz) merge!(baz) end end ``` This change fixes that.
When running
merge!
on an implicitself
, rubocop raisesundefined method
source' for nil:NilClass`.Expected behavior
No error
Actual behavior
Error in
RuboCop::Cop::Performance::RedundantMerge#to_assignments
.Stacktrace:
Steps to reproduce the problem
The error occurred because
merge!
was being called implicitly onself
in the class:So the
receiver
onrubocop/cop/performance/redundant_merge.rb:94
wasnil
. Changing my code tofixes the error, but should not be necessary.
RuboCop version
Ruby version
The text was updated successfully, but these errors were encountered: