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

Space around keyword produces misleading results for super #3116

Closed
rwz opened this issue May 8, 2016 · 8 comments
Closed

Space around keyword produces misleading results for super #3116

rwz opened this issue May 8, 2016 · 8 comments
Labels

Comments

@rwz
Copy link

rwz commented May 8, 2016

def my_method
  super&.a_method_on_super
end

This code produces an offense of Style/SpaceAroundKeyword: Space after keyword super is missing.

Seems like a false positive to me.

@owst
Copy link
Contributor

owst commented May 9, 2016

Can you give a minimal reproducible example? I tried your code, but contains a syntax error:

> cat foo.rb
def my_method
  super&.a_method_on_super
end
> ruby foo.rb
foo.rb:2: syntax error, unexpected '.'
  super&.a_method_on_super
         ^

So I removed the &, but that code gives no error for me:

> rubocop foo.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

I'm running rubocop: 0.39.0 (using Parser 2.3.1.0, running on ruby 2.2.3 x86_64-darwin14).

Can you provide the output of running rubocop -V?

@rwz
Copy link
Author

rwz commented May 9, 2016

The code sample uses ruby 2.3 safe navigation syntax, so you need at least ruby version 2.3.0 for it to work.

The rubocop version is:

0.39.0 (using Parser 2.3.1.0, running on ruby 2.3.1 x86_64-darwin15)

@rwz
Copy link
Author

rwz commented May 9, 2016

Minimal example using ruby 2.3:

foo.rb

def my_method
  super&.a_method_on_super
end

.rubocop.yml

AllCops:
  DisabledByDefault: true
  TargetRubyVersion: 2.3

Style/SpaceAroundKeyword:
  Description: "Use a space around keywords if appropriate."
  Enabled: true

output:

$ rubocop -V
0.40.0 (using Parser 2.3.1.0, running on ruby 2.3.1 x86_64-darwin15)

$ rubocop -D foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:2:3: C: Style/SpaceAroundKeyword: Space after keyword super is missing.
  super&.a_method_on_super
  ^^^^^

1 file inspected, 1 offense detected

@rwz
Copy link
Author

rwz commented May 9, 2016

As seen from the example, updating to 0.40 didn't change much.

@segiddins
Copy link
Contributor

I have a fix for this locally, about to make a PR

@bbatsov bbatsov added the bug label May 10, 2016
@owst
Copy link
Contributor

owst commented May 10, 2016

Aha, of course, I forgot about the new safe navigation operator (I'm stuck on 2.2.3 at work, so haven't used it)! Thanks for adding the example @rwz, sounds like a fix is incoming shortly.

@tejasbubane
Copy link
Contributor

Fixed in #3118. This can be closed @rwz

@segiddins Going further please add something like fixes #<issue_number> to your PR description so that it automatically closes the associated issue. Read more about it here.

@rwz
Copy link
Author

rwz commented May 20, 2016

Cool, thanks for taking care of it! 👍

@rwz rwz closed this as completed May 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants