Skip to content

Commit

Permalink
[Fix #9914] Fix an error for Layout/HashAlignment
Browse files Browse the repository at this point in the history
Fixes #9914.

This PR fixes an error for `Layout/HashAlignment`
when using aligned hash argument for `proc.()`.
  • Loading branch information
koic authored and bbatsov committed Jul 6, 2021
1 parent e18a043 commit e758a0d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_layout_hash_alignment.md
@@ -0,0 +1 @@
* [#9914](https://github.com/rubocop/rubocop/issues/9914): Fix an error for `Layout/HashAlignment` when using aligned hash argument for `proc.()`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/hash_alignment.rb
Expand Up @@ -220,7 +220,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.selector.line == node.pairs.first.loc.line
node.parent&.call_type? && node.parent.loc.selector&.line == node.pairs.first.loc.line
end

def reset!
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/layout/hash_alignment_spec.rb
Expand Up @@ -177,6 +177,12 @@ def example
foo({})
RUBY
end

it 'does not register an offense using aligned hash argument for `proc.()`' do
expect_no_offenses(<<~RUBY)
proc.(key: value)
RUBY
end
end

context 'always ignore last argument hash' do
Expand Down

0 comments on commit e758a0d

Please sign in to comment.