Skip to content

Commit

Permalink
Merge pull request #12631 from koic/fix_a_false_positive_for_layout_r…
Browse files Browse the repository at this point in the history
…edundant_line_break_cop

[Fix #12627] Fix a false positive for `Layout/RedundantLineBreak`
  • Loading branch information
koic committed Jan 18, 2024
2 parents 2b27ed8 + 3cf1bce commit 20353dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
@@ -0,0 +1 @@
* [#12627](https://github.com/rubocop/rubocop/issues/12627): Fix a false positive for `Layout/RedundantLineBreak` when using index access call chained on multiple lines with backslash. ([@koic][])
6 changes: 5 additions & 1 deletion lib/rubocop/cop/layout/redundant_line_break.rb
Expand Up @@ -85,7 +85,11 @@ def register_offense(node)

def offense?(node)
node.multiline? && !too_long?(node) && suitable_as_single_line?(node) &&
!configured_to_not_be_inspected?(node)
!index_access_call_chained?(node) && !configured_to_not_be_inspected?(node)
end

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

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

it 'does not register an offense for index access call chained on multiple lines with backslash' do
expect_no_offenses(<<~RUBY)
hash[:foo] \\
[:bar]
RUBY
end

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

Expand Down

0 comments on commit 20353dc

Please sign in to comment.