Skip to content

False positive on Style/RedundantLineContinuation #12627

@robingram

Description

@robingram

Expected behavior

File test.rb:

h = {very: {deep: {nested: {hash: false}}}}

val = h[:very] \
  [:deep] \
  [:nested] \
  [:hash]

puts val

Running bundle exec rubocop test.rb --only Style/RedundantLineContinuation does not highlight any errors.

Running ruby test.rb produces the output false.

Actual behavior

Running bundle exec rubocop test.rb --debug --only Style/RedundantLineContinuation produces

C

Offenses:

test.rb:3:16: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
val = h[:very] \ ...
               ^
test.rb:4:11: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
  [:deep] \ ...
          ^
test.rb:5:13: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
  [:nested] \ ...
            ^

1 file inspected, 3 offenses detected, 3 offenses autocorrectable

Running bundle exec rubocop test.rb --fix --only Style/RedundantLineContinuation removes the line continuations. After this, running ruby test.rb outputs:

{:deep=>{:nested=>{:hash=>false}}}

Steps to reproduce the problem

Create a file called test.rb containing the code from above. Run bundle exec rubocop test.rb --only Style/RedundantLineContinuation.

RuboCop version

bundle exec rubocop -V
1.59.0 (using Parser 3.3.0.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin22]

Also:

rubocop _1.60.0_ -V                                             
1.60.0 (using Parser 3.3.0.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin22]

rubocop _1.60.0_  --only Style/RedundantLineContinuation test.rb
Inspecting 1 file
C

Offenses:

test.rb:3:16: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
val = h[:very] \ ...
               ^
test.rb:4:11: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
  [:deep] \ ...
          ^
test.rb:5:13: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
  [:nested] \ ...
            ^

1 file inspected, 3 offenses detected, 3 offenses autocorrectable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy