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

False positive for Style/HashAsLastArrayItem when the array is implicit #8740

Closed
dvandersluis opened this issue Sep 16, 2020 · 0 comments · Fixed by #8741
Closed

False positive for Style/HashAsLastArrayItem when the array is implicit #8740

dvandersluis opened this issue Sep 16, 2020 · 0 comments · Fixed by #8741

Comments

@dvandersluis
Copy link
Member

Style/HashAsLastArrayItem detects and corrects hashes in an implicit array (such as when passing multiple values to a setter), resulting in a syntax error.


Expected behavior

The following is a common line of code in Rails projects:

config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL']  }

It should not register an offense, as the braces are necessary syntax.

Actual behavior

Rubocop registers an offense:

bundle exec rubocop bug.rb -A --only Style/HashAsLastArrayItem
bug.rb:1:42: C: Style/HashAsLastArrayItem: Omit the braces around the hash.
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^

And corrects to:

config.cache_store = :redis_cache_store,  url: ENV['REDIS_URL'] 

Which is a syntax error:

$ ruby bug.rb
bug.rb:1: syntax error, unexpected tLABEL
...ore = :redis_cache_store,  url: ENV['REDIS_URL']

RuboCop version

$ rubocop -V
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.6.2 x86_64-darwin18)
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 16, 2020
koic added a commit that referenced this issue Sep 17, 2020
…licit

[Fix #8740] Fix a false positive for `Style/HashAsLastArrayItem` when the hash is in an implicit array
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