Rubocop: Layout/IndentAssignment removes nested indentation

Created on 4 Oct 2019  路  4Comments  路  Source: rubocop-hq/rubocop

When reviewing rubocop-0.75.0 dependabot PR for my project I encountered the offence: Layout/IndentAssignment: Indent the first line of the right-hand-side of a multi-line assignment.

Originally this was

    Rails.application.env_config['omniauth.auth'] =
      OmniAuth.config.mock_auth[identity.provider.to_sym] =
        OmniAuth::AuthHash.new(provider: identity.provider,
                               uid: identity.uid)

and then corrected to

    Rails.application.env_config['omniauth.auth'] =
      OmniAuth.config.mock_auth[identity.provider.to_sym] =
      OmniAuth::AuthHash.new(provider: identity.provider,
                             uid: identity.uid)

Expected behavior

bad scenario gets corrected to good

# bad
value =
  a =
  b = 42

# good
value =
  a =
    b = 42

Actual behavior

good scenario gets corrected to bad
C: [Corrected] Layout/IndentAssignment: Indent the first line of the right-hand-side of a multi-line assignment.
b = 42

# bad
value =
  a =
  b = 42

# good
value =
  a =
  b = 42

Steps to reproduce the problem

copy the example above to a file and run rubocop -a to observe the correction

RuboCop version

$ rubocop -V
0.75.0 (using Parser 2.6.5.0, running on ruby 2.5.3 x86_64-linux)
bug

Most helpful comment

git bisect tells me

3754a74d504b5f04d1f4cb28b874fb31b37f9eba is the first bad commit
commit 3754a74d504b5f04d1f4cb28b874fb31b37f9eba
Author: Koichi ITO <[email protected]>
Date:   Thu Sep 19 13:11:26 2019 +0900

    [Fix #7369] Fix an infinite loop error for `Layout/IndentAssignment`

    Fixes #7369.

    This PR fixes an infinite loop error for `Layout/IndentAssignment` with
    `Layout/IndentFirstArgument` when using multiple assignment.

@koic Can you take a deeper look?

All 4 comments

Seems like some regression indeed. @buehmann You were doing some changes in this area, right? Can you take a look at the problem?

git bisect tells me

3754a74d504b5f04d1f4cb28b874fb31b37f9eba is the first bad commit
commit 3754a74d504b5f04d1f4cb28b874fb31b37f9eba
Author: Koichi ITO <[email protected]>
Date:   Thu Sep 19 13:11:26 2019 +0900

    [Fix #7369] Fix an infinite loop error for `Layout/IndentAssignment`

    Fixes #7369.

    This PR fixes an infinite loop error for `Layout/IndentAssignment` with
    `Layout/IndentFirstArgument` when using multiple assignment.

@koic Can you take a deeper look?

@buehmann Ops, sorry about the false alarm! And thanks to taking the time to find the real cause of the issue! 馃檱

@buehmann Thanks for the mention. I opened a PR #7416.

Was this page helpful?
0 / 5 - 0 ratings