diff --git a/changelog/fix_an_error_for_layout_hash_alignment.md b/changelog/fix_an_error_for_layout_hash_alignment.md new file mode 100644 index 00000000000..282dd3237b8 --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/layout/hash_alignment.rb b/lib/rubocop/cop/layout/hash_alignment.rb index 9ff70a1d94e..d94b5291fac 100644 --- a/lib/rubocop/cop/layout/hash_alignment.rb +++ b/lib/rubocop/cop/layout/hash_alignment.rb @@ -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! diff --git a/spec/rubocop/cop/layout/hash_alignment_spec.rb b/spec/rubocop/cop/layout/hash_alignment_spec.rb index 946c06ac3b2..2b41ae05610 100644 --- a/spec/rubocop/cop/layout/hash_alignment_spec.rb +++ b/spec/rubocop/cop/layout/hash_alignment_spec.rb @@ -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