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

Make Style/RedundantSelf accept self.() #3553

Merged
merged 1 commit into from
Oct 22, 2016

Conversation

iGEL
Copy link
Contributor

@iGEL iGEL commented Sep 29, 2016

To send .() (an alternative to .call) to self, you have to explicitly call self. However Style/RedundantSelf cop was registering an offence for self.(). Probably is also allows
self.call, but I hope we can live with that.

@iGEL iGEL force-pushed the not-redundant-self branch 2 times, most recently from 31e6f99 to 93c6172 Compare September 30, 2016 06:58
@iGEL iGEL changed the title Allow self.() Make Style/RedundantSelf accept self.() Sep 30, 2016
@iGEL
Copy link
Contributor Author

iGEL commented Sep 30, 2016

Can someone help me with this failure? It seems unrelated and I can't reproduce it locally with this Dockerfile:

FROM ruby:2.1.10
WORKDIR /code
ADD . /code/
RUN bundle install
CMD bundle exec rake

@@ -123,7 +123,8 @@ def regular_method_call?(node)
!(operator?(method_name) ||
keyword?(method_name) ||
constant_name?(method_name) ||
node.asgn_method_call?)
node.asgn_method_call? ||
method_name == :call)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's not good enough - it will match both self.() and self.call.

@@ -187,6 +187,12 @@
expect(cop.offenses).to be_empty
end

it 'accepts a self receiver of .()' do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also have a test that this doesn't accept self.call.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 30, 2016

Seems the failure was random.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 5, 2016

@iGEL ping :-)

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 18, 2016

@iGEL Ping 2 :-)

@iGEL
Copy link
Contributor Author

iGEL commented Oct 18, 2016

@bbatsov Pong :-)

Hope it's fine now, I don't have much experience working with the AST or developing for Rubocop.

@@ -143,6 +144,10 @@ def constant_name?(method_name)
method_name.match(/^[A-Z]/)
end

def braces_style_call?(node)
node.source.start_with?('self.(')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.loc.selector.nil? is a way more efficient way to check for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

To send `.()` (an alternative to `.call`) to `self`, you have to
explicitly call `self`. However `Style/RedundantSelf` cop was
registering an offence for `self.()`.
@bbatsov bbatsov merged commit 67a5c52 into rubocop:master Oct 22, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 22, 2016

👍

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.

2 participants