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

False positive for MultilineOperationIndentation #7094

Closed
taichi-ishitani opened this issue May 31, 2019 · 3 comments
Closed

False positive for MultilineOperationIndentation #7094

taichi-ishitani opened this issue May 31, 2019 · 3 comments
Labels

Comments

@taichi-ishitani
Copy link
Contributor

Expected behavior

When enforce style of Layout/MultilineOperationIndentation cop is aligned Rubocop should report no offences for multi-line operation without assignment like below.

# frozen_string_literal: true

a = true
b = false

a &&
b

Actual behavior

Rubocop reports MultilineOperationIndentation offence with following message:

sample.rb:7:1: C: Layout/MultilineOperationIndentation: Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
b
^

Steps to reproduce the problem

Unzip attached zip file and run command below.
sample.zip

Then you can reproduce this issue.

$ rubocop -c sample.yml sample.rb
Inspecting 1 file
C

Offenses:

sample.rb:7:1: C: Layout/MultilineOperationIndentation: Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
b
^

1 file inspected, 1 offense detected

RuboCop version

$ rubocop -V
0.71.0 (using Parser 2.6.0.0, running on ruby 2.5.3 x64-mingw32)
@stale
Copy link

stale bot commented Aug 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Aug 29, 2019
@Drenmi Drenmi added bug and removed stale Issues that haven't been active in a while labels Aug 29, 2019
@koic
Copy link
Member

koic commented Nov 26, 2019

As far as I read the test code, this is the expected behavior common to both EnforcedStyle: aligned (default) and EnforcedStyle: indented. And I think this behavior makes sense.

shared_examples 'common' do
  (snip)

  it 'registers an offense for no indentation of second line' do
    expect_offense(<<~RUBY)
      a +
      b
      ^ Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
    RUBY
  end

https://github.com/rubocop-hq/rubocop/blob/v0.76.0/spec/rubocop/cop/layout/multiline_operation_indentation_spec.rb#L46-L52

I think example code and/or documentation should be added if the test code is correct.

@taichi-ishitani
Copy link
Contributor Author

Hi @koic ,
Thank you for you comment and I understand this is the expected behavior.
I'm not sure whether or not this is the valid behavior because there are no sample code. So I open this ticket.

jonas054 added a commit to jonas054/rubocop that referenced this issue Apr 19, 2020
Update the cop documentation to make it more clear which operands should be
aligned, and which should always be indented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants