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

Style/HashAsLastArrayItem for array of hashes #8617

Closed
dvandersluis opened this issue Aug 28, 2020 · 0 comments · Fixed by #8635
Closed

Style/HashAsLastArrayItem for array of hashes #8617

dvandersluis opened this issue Aug 28, 2020 · 0 comments · Fixed by #8635

Comments

@dvandersluis
Copy link
Member

I believe this might be similar to #8409, but the reverse. When EnforcedStyle is no_braces, Style/HashAsLastArrayItem is a bit over-zealous IMO when it comes to an array of only hashes, and suggests removing the outer braces for the last element, which is going to lead to confusion.

Can the cop be updated to not consider arrays that are only hashes?


Expected behavior

Cop should not find any offense with this code with EnforcedStyle: no_braces:

QUOTES = [
  {
    background_color: '#EE0F0F',
    id: 2987584,
    quote_author_id: 8202,
    quote_author_title: 'John Smith',
    image_filename: 'image-2987584.png'
  },
  {
    background_color: '#EE0F0F',
    id: 2948124,
    quote_author_id: 1709304,
    quote_author_title: 'Tim Brown',
    image_filename: 'image-2948124.png'
  }
].freeze

Actual behavior

The cop registers offenses for the outer braces on the last element, and autocorrects them away:

QUOTES = [
  {
    background_color: '#EE0F0F',
    id: 2987584,
    quote_author_id: 8202,
    quote_author_title: 'John Smith',
    image_filename: 'image-2987584.png'
  },

  background_color: '#EE0F0F',
  id: 2948124,
  quote_author_id: 1709304,
  quote_author_title: 'Tim Brown',
  image_filename: 'image-2948124.png'
].freeze

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ [bundle exec] rubocop -V
0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.6.2 x86_64-darwin18)
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 4, 2020
bbatsov pushed a commit that referenced this issue Sep 7, 2020
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