Skip to content

Commit

Permalink
Fix Layout/RedundantLineBreak adding extra space within method chains.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandersluis committed Sep 24, 2021
1 parent 05494a4 commit c3bf154
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_layoutredundantlinebreak_adding.md
@@ -0,0 +1 @@
* [#10124](https://github.com/rubocop/rubocop/pull/10124): Fix `Layout/RedundantLineBreak` adding extra space within method chains. ([@dvandersluis][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/layout/redundant_line_break.rb
Expand Up @@ -128,6 +128,7 @@ def to_single_line(source)
.gsub(/' *\\\n\s*"/, %q(' + ")) # Single quote, backslash, and then double quote
.gsub(/(["']) *\\\n\s*\1/, '') # Double or single quote, backslash, then same quote
.gsub(/\s*\\?\n\s*/, ' ') # Any other line break, with or without backslash
.gsub(/\s+(?=\.\w)/, '') # Extra space within method chaining
end

def max_line_length
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/layout/redundant_line_break_spec.rb
Expand Up @@ -271,6 +271,19 @@ def resolve_inheritance_from_gems(hash)
m(7 + 8 + 9)
RUBY
end

it 'properly corrects a method chain on multiple lines' do
expect_offense(<<~RUBY)
foo
^^^ Redundant line break detected.
.bar
.baz
RUBY

expect_correction(<<~RUBY)
foo.bar.baz
RUBY
end
end

context 'for an expression that does not fit on a single line' do
Expand Down

0 comments on commit c3bf154

Please sign in to comment.