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

Conflict between Layout/ArgumentAlignment and Layout/FirstHashElementIndentation #9829

Closed
natematykiewicz opened this issue May 26, 2021 · 3 comments

Comments

@natematykiewicz
Copy link

natematykiewicz commented May 26, 2021

Given the config:

Layout/ArgumentAlignment:
  EnforcedStyle: with_first_argument # (default)
Layout/FirstHashElementIndentation:
  EnforcedStyle: consistent # (non-default)

With this code:

it do
  is_expected.to contain_exactly(
    {
      a: 1, # <-- Layout/ArgumentAlignment
      b: 2, # <-- Layout/ArgumentAlignment
      c: 3, # <-- Layout/ArgumentAlignment
    },
    {
      a: 2,
      b: 3,
      c: 4,
    }
  )
end

Layout/ArgumentAlignment offenses are registered on the 3 indicated lines.

It seems that Layout/ArgumentAlignment wants this:

it do
  is_expected.to contain_exactly(
    {
    a: 1, # <-- Layout/FirstHashElementIndentation
    b: 2,
    c: 3,
    },
    {
      a: 2,
      b: 3,
      c: 4,
    }
  )
end

This looks odd, but also then causes a violation on Layout/FirstHashElementIndentation.

Layout/FirstHashElementIndentation seems to want this:

it do
  is_expected.to contain_exactly(
    {
      a: 1, # <-- Layout/ArgumentAlignment
    b: 2,
    c: 3,
    },
    {
      a: 2,
      b: 3,
      c: 4,
    }
  )
end

Expected behavior

This should be acceptable:

it do
  is_expected.to contain_exactly(
    {
      a: 1,
      b: 2,
      c: 3,
    },
    {
      a: 2,
      b: 3,
      c: 4,
    }
  )
end

Actual behavior

Rubocop is impossible to please and hits an infinite loop attempting to autocorrect.

Infinite loop detected in app/controllers/graphql_controller.rb and caused by Layout/FirstHashElementIndentation -> Layout/ArgumentAlignment

Steps to reproduce the problem

Run Rubocop using the config and code specified above.

RuboCop version

$ bundle exec rubocop -V
1.15.0 (using Parser 3.0.1.1, rubocop-ast 1.5.0, running on ruby 2.5.1 x86_64-linux)
  - rubocop-performance 1.11.3
  - rubocop-rails 2.10.1
  - rubocop-rspec 2.3.0
@natematykiewicz
Copy link
Author

Is this possibly the fix, and I just need to wait? #9805
Note: I'm using Layout/FirstHashElementIndentation of EnforcedStyle: consistent where #9805 mentions EnforcedStyle: with_fixed_indentation. But maybe that's still the same problem.

@koic
Copy link
Member

koic commented May 27, 2021

Is this possibly the fix, and I just need to wait? #9805

#9812 will also be required to resolve this issue. Please wait for the next release as it has been fixed in master branch. Thank you.

@koic koic closed this as completed May 27, 2021
@koic koic added the duplicate label May 27, 2021
@natematykiewicz
Copy link
Author

Excellent. Thanks @koic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants