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 negative with Layout/HashAlignment with table style #9888

Open
edouard-per-angusta opened this issue Jun 22, 2021 · 2 comments
Open

False negative with Layout/HashAlignment with table style #9888

edouard-per-angusta opened this issue Jun 22, 2021 · 2 comments
Labels

Comments

@edouard-per-angusta
Copy link

When a key follows a longer one, the following key has a warning:

Screenshot 2021-06-22 at 09 11 30


Expected behavior

There shouldn't be any warning.

Actual behavior

There is a warning:

Screenshot 2021-06-22 at 09 15 09

Running rubocop -A adds an extra space:

Screenshot 2021-06-22 at 09 25 34

Steps to reproduce the problem

Create a folder with these files:

# .rubocop.yml

Layout/HashAlignment:
  EnforcedHashRocketStyle: table
  EnforcedColonStyle: table
# example.rb

FOO = {
  a:  1,
  bb: 2,
  c:  3
}.freeze

RuboCop version

$ rubocop -V
1.15.0 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.6.7 x86_64-darwin20)
  - rubocop-performance 1.11.3
  - rubocop-rails 2.10.1
  - rubocop-rspec 2.3.0
@rrosenblum
Copy link
Contributor

hmm, it seems to somehow want to align with the comma rather than the value itself. This certainly seems like a bug. I've run into some other conditions recently that HashAlignment doesn't seem to be picking up. My issues have mainly been with dealing with values that appear on the next line. I haven't had too much time to dig into what's going on.

@koic koic added the bug label Jun 29, 2021
@AndreiEres
Copy link

AndreiEres commented Sep 8, 2021

Interesting, I can't catch the problem in hash_alignment_spec.rb. All specs passed.

  context 'with table alignment configuration' do
    let(:cop_config) do
      {
        'EnforcedHashRocketStyle' => 'table',
        'EnforcedColonStyle' => 'table'
      }
    end

    it '' do
      expect_no_offenses(<<~RUBY)
        FOO = {
          a:  1,
          bb: 2,
          c:  3
        }.freeze
      RUBY
    end
  end

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

4 participants