-
-
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
Make Style/RedundantSelf accept self.() #3553
Conversation
31e6f99
to
93c6172
Compare
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
Seems the failure was random. |
@iGEL ping :-) |
@iGEL Ping 2 :-) |
93c6172
to
a3f8428
Compare
a3f8428
to
9b6b87f
Compare
@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.(') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.()`.
9b6b87f
to
980b2ee
Compare
👍 |
To send
.()
(an alternative to.call
) toself
, you have to explicitly callself
. HoweverStyle/RedundantSelf
cop was registering an offence forself.()
. Probably is also allowsself.call
, but I hope we can live with that.