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 misses case inside block #10311

Closed
mockdeep opened this issue Dec 22, 2021 · 0 comments
Closed

Layout/RedundantLineBreak misses case inside block #10311

mockdeep opened this issue Dec 22, 2021 · 0 comments

Comments

@mockdeep
Copy link
Contributor

Expected behavior

Given the below code, I would expect the Layout/RedundantLineBreak rule to report that the line inside the block should not be wrapped. Note: our line length is set to 84 and InspectBlocks is set to false.

some_array.map do |something|
  my_slightly_long_but_not_that_long_method(
    something,
  )
end

The code should be enforced to not wrap:

some_array.map do |something|
  my_slightly_long_but_not_that_long_method(something)
end

Actual behavior

Rubocop does not report an error. If I add another line to the block it does report an issue:

some_array.map do |something|
  foo
  my_slightly_long_but_not_that_long_method(
    something,
  )
end

# C: [Correctable] Layout/RedundantLineBreak: Redundant line break detected.                                                                                                
#  my_slightly_long_but_not_that_long_method( ...
#  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

RuboCop version

$ rubocop -V
1.23.0 (using Parser 3.0.3.2, rubocop-ast 1.15.0, running on ruby 2.7.5 x86_64-linux)
  - rubocop-performance 1.12.0
  - rubocop-rails 2.12.4
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.6.0
jonas054 added a commit to jonas054/rubocop that referenced this issue Mar 26, 2022
When Layout/RedundantLineBreak inspects a send node, it starts by
expanding the node to inspect. It does this by traversing the AST
upwards as long as the parent is a send node of a block node.

The problem was that if the inspected node is a single node inside
a do..end block, we shouldn't move to the parent block and inspect
it for redundant line breaks. It's only send nodes before the
do..end that we want to expand in order to inspect "the whole
expression". So we should check what kind of block/send
relationship it is before moving upwards in the AST.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant