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

New Layout/AlignHash has a runtime error on mixed Hash style #7066

Closed
kmoschcau opened this issue May 21, 2019 · 2 comments · Fixed by #7068
Closed

New Layout/AlignHash has a runtime error on mixed Hash style #7066

kmoschcau opened this issue May 21, 2019 · 2 comments · Fixed by #7068

Comments

@kmoschcau
Copy link

Expected behavior

Rubocop should run the Layout/AlignHash cop without an error occuring.

Actual behavior

There occurs an error with the message "nil can't be coerced into Integer"

Steps to reproduce the problem

Minimal example:

bar(
  foo:  'baz',
  'bar' => 'bla'
)

RuboCop version

$ [bundle exec] rubocop -V
0.70.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-linux)
@rmm5t
Copy link
Contributor

rmm5t commented May 21, 2019

I just ran into this as well, here was our specific use-case:

      {
        'Content-Type' => 'application/json',
        Authorization: "Bearer #{@access_token}",
      }
$ rubocop -V
0.70.0 (using Parser 2.6.3.0, running on ruby 2.5.3 x86_64-darwin18)
# Allow for either `key` or `table` alignment for hashes
Layout/AlignHash:
  EnforcedHashRocketStyle:
    - key
    - table
  EnforcedColonStyle:
    - key
    - table
  EnforcedLastArgumentHashStyle: ignore_implicit
An error occurred while Layout/AlignHash cop was inspecting /Users/rmcgeary/work/ironridge/lib/salesforce/client.rb:72:6.
nil can't be coerced into Integer
.../gems/rubocop-0.70.0/lib/rubocop/cop/mixin/hash_alignment.rb:113:in `+'
.../gems/rubocop-0.70.0/lib/rubocop/cop/mixin/hash_alignment.rb:113:in `value_delta'
.../gems/rubocop-0.70.0/lib/rubocop/cop/mixin/hash_alignment.rb:65:in `deltas'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:239:in `block (2 levels) in check_pairs'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:238:in `each'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:238:in `block in check_pairs'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:237:in `each'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:237:in `check_pairs'
.../gems/rubocop-0.70.0/lib/rubocop/cop/layout/align_hash.rb:208:in `on_hash'

@rmm5t
Copy link
Contributor

rmm5t commented May 21, 2019

PR ready for review here: #7068

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

Successfully merging a pull request may close this issue.

2 participants