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

Layout/SpaceInsideHashLiteralBraces does not find all violations in some situations and has to be run at least twice #8642

Closed
eric-christian opened this issue Sep 3, 2020 · 0 comments · Fixed by #8649

Comments

@eric-christian
Copy link

eric-christian commented Sep 3, 2020

Expected behavior

I expect the cop to find all violations:

❯ rubocop demo.rb
Inspecting 1 file
C

Offenses:

demo.rb:8:3: C: Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
  {key: 1}
  ^
demo.rb:8:10: C: Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
  {key: 1}
         ^

1 file inspected, 2 offenses detected, 2 offenses auto-correctable

Actual behavior

It only finds one violation:

❯ rubocop demo.rb
Inspecting 1 file
C

Offenses:
demo.rb:8:3: C: Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
  {key: 1}
  ^

1 file inspected, 1 offense detected, 1 offense auto-correctable

Steps to reproduce the problem

Create the file demo.rb:

# frozen_string_literal: true

def abc
  {}
end

def xyz
  {key: 1}
end

Run rubocop:

❯ rubocop demo.rb

I don't know why, but the method body of abc is relevant. If you change it from {} to for example 'a string', then the cop works as expected.

RuboCop version

❯ rubocop -V
0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.7.1 x86_64-darwin19)
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 10, 2020
…eralBraces` when a correct empty hash precedes the incorrect hash.
koic added a commit that referenced this issue Sep 10, 2020
…ral-braces-false-negative

[Fix #8642] Fix a false negative for `Style/SpaceInsideHashLiteralBraces` when a correct empty hash precedes the incorrect hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant