Skip to content
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

Fix Style/MethodCallParentheses failed on or assign to instance vaiable's accessor #2393

Closed

Conversation

yuroyoro
Copy link

@yuroyoro yuroyoro commented Nov 4, 2015

Style/MethodCallParentheses failed on following code.

@foo.bar ||= puts()

This is a backtrace log that reported with running rubocop -d --only Style/MethodCallParentheses.

$ rubocop --only Style/MethodCallParentheses sample.rb -d
Inspecting 1 file
Scanning /home/ozaki/dev/rubocop_sample/sample.rb
For /home/ozaki/dev/rubocop_sample: configuration from /home/ozaki/dev/rubocop_sample/.rubocop.yml
Default configuration from /home/ozaki/dev/rubocop_sample/vendor/bundle/ruby/2.1.0/gems/rubocop-0.34.2/config/default.yml
Inheriting configuration from /home/ozaki/dev/rubocop_sample/vendor/bundle/ruby/2.1.0/gems/rubocop-0.34.2/config/enabled.yml
Inheriting configuration from /home/ozaki/dev/rubocop_sample/vendor/bundle/ruby/2.1.0/gems/rubocop-0.34.2/config/disabled.yml
.

1 file inspected, no offenses detected
Finished in 0.04518964 seconds

I corrected lib/rubocop/cop/style/method_call_parentheses.rb to check the asgn_node.loc respond to name.
(I wonder this is right way to fix this bug...)

@yuroyoro yuroyoro force-pushed the method_call_parentheses_on_or_assign branch from 32f414a to ec8f492 Compare November 4, 2015 05:32
@alexdowad
Copy link
Contributor

Thanks for reporting this issue! But the "fix" doesn't go to the root of the bug.

Your code produces the following AST:

(or-asgn
  (send (ivar :@foo) :bar)
  (send nil :puts))

The problem is that asgn_node.loc is returning the Parser::Source::Map of its first child, (send (ivar :foo) :bar). Why? I don't know yet.

Until you know exactly what is causing the problem, you can't know what the correct fix is.

@alexdowad
Copy link
Contributor

OK, I was wrong. It's normal for asgn_node.loc to return that value in this case.

@alexdowad
Copy link
Contributor

I've found the problem.

alexdowad added a commit to alexdowad/rubocop that referenced this pull request Nov 4, 2015
@bbatsov bbatsov closed this in #2394 Nov 4, 2015
bbatsov added a commit that referenced this pull request Nov 4, 2015
[Fix #2393] `Style/MethodCallParentheses` doesn't fail on `obj.method ||= func()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants