Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout/RedundantLineBreak modifies multiline strings #11949

Closed
naveg opened this issue Jun 13, 2023 · 0 comments · Fixed by #11950
Closed

Layout/RedundantLineBreak modifies multiline strings #11949

naveg opened this issue Jun 13, 2023 · 0 comments · Fixed by #11950
Labels

Comments

@naveg
Copy link
Contributor

naveg commented Jun 13, 2023

Layout/RedundantLineBreak is not respecting multiline strings. Consider this example, foo.rb:

# frozen_string_literal: true

foo = 'this is
  a string
 with    some
     funky
  but valid
   whitespace
'

puts foo

and this rubocop config .rubocop.yml:

AllCops:
  NewCops: enable

Layout/RedundantLineBreak:
  Enabled: true

Expected behavior

This code is valid Ruby, and Ruby respects the whitespace as written. Running the program results in this output:

❯ ruby foo.rb
this is
  a string
 with    some
     funky
  but valid
   whitespace

As such, RuboCop should not flag any offenses.

Actual behavior

RuboCop flags a Layout/RedundantLineBreak offense, and modifies the code. The resulting program behaves differently.

❯ rubocop -a foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:3:1: C: [Corrected] Layout/RedundantLineBreak: Redundant line break detected.
foo = 'this is ...
^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

❯ cat foo.rb
# frozen_string_literal: true

foo = 'this is a string with    some funky but valid whitespace '

puts foo

❯ ruby foo.rb
this is a string with    some funky but valid whitespace

RuboCop version

❯ rubocop -V
1.52.1 (using Parser 3.2.2.3, rubocop-ast 1.28.1, running on ruby 3.2.0) [arm64-darwin22]
❯ ruby --version
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22]
@koic koic added the bug label Jun 14, 2023
koic added a commit to koic/rubocop that referenced this issue Jun 14, 2023
Fixes rubocop#11949.

This PR fixes a false positive for `Layout/RedundantLineBreak`
when using a line broken string.
koic added a commit that referenced this issue Jun 14, 2023
…edundant_line_break

[Fix #11949] Fix a false positive for `Layout/RedundantLineBreak`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants