Skip to content

Commit

Permalink
Merge pull request #12656 from koic/fix_error_for_layout_redundant_li…
Browse files Browse the repository at this point in the history
…ne_break

Fix an error for `Layout/RedundantLineBreak`
  • Loading branch information
koic committed Jan 28, 2024
2 parents d1746be + a3a30d4 commit bededcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_error_for_layout_redundant_line_break.md
@@ -0,0 +1 @@
* [#12656](https://github.com/rubocop/rubocop/pull/12656): Fix an error for `Layout/RedundantLineBreak` when using index access call chained on multiline hash literal. ([@koic][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/layout/redundant_line_break.rb
Expand Up @@ -89,7 +89,9 @@ def offense?(node)
end

def index_access_call_chained?(node)
node.send_type? && node.method?(:[]) && node.children.first.method?(:[])
return false unless node.send_type? && node.method?(:[])

node.children.first.send_type? && node.children.first.method?(:[])
end

def configured_to_not_be_inspected?(node)
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/layout/redundant_line_break_spec.rb
Expand Up @@ -159,6 +159,19 @@
RUBY
end

it 'registers an offense for index access call chained on multiline hash literal' do
expect_offense(<<~RUBY)
{
^ Redundant line break detected.
key: value
}[key]
RUBY

expect_correction(<<~RUBY)
{ key: value }[key]
RUBY
end

context 'with LineLength Max 100' do
let(:max_line_length) { 100 }

Expand Down

0 comments on commit bededcc

Please sign in to comment.