Skip to content

Commit

Permalink
[Fix rubocop#9861] Fix error in Layout/HashAlignment with an empty …
Browse files Browse the repository at this point in the history
…hash literal.
  • Loading branch information
dvandersluis committed Jun 9, 2021
1 parent 7dd734f commit e6c2aa9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_error_in_layouthashalignment_with_an.md
@@ -0,0 +1 @@
* [#9861](https://github.com/rubocop/rubocop/issues/9861): Fix error in `Layout/HashAlignment` with an empty hash literal. ([@dvandersluis][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/layout/hash_alignment.rb
Expand Up @@ -218,6 +218,7 @@ def on_hash(node)

def autocorrect_incompatible_with_other_cops?(node)
enforce_first_argument_with_fixed_indentation? &&
node.pairs.any? &&
node.parent&.call_type? && node.parent.loc.line == node.pairs.first.loc.line
end

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/layout/hash_alignment_spec.rb
Expand Up @@ -171,6 +171,12 @@ def example
}
RUBY
end

it 'does not register an offense for an empty hash literal' do
expect_no_offenses(<<~RUBY)
foo({})
RUBY
end
end

context 'always ignore last argument hash' do
Expand Down

0 comments on commit e6c2aa9

Please sign in to comment.