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

Layout/HashAlignment failing for empty or double splat hash in method call argument #9872

Closed
Achooo opened this issue Jun 11, 2021 · 2 comments

Comments

@Achooo
Copy link

Achooo commented Jun 11, 2021

Expected behavior

We expect no rubocop errors with Layout/HashAlignment turned on by default for empty hashes or double splat operators as method arguments

Actual behavior

We get errors for empty hashes{} and the double splat operator ** passed as method arguments:

$ bin/rubocop test.rb --debug
For /Users/<omitted_path>: configuration from /Users/<omitted_path>/.rubocop.yml
Inheriting configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-<omitted>-2.1.0/rubocop.yml
Default configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/config/default.yml
Inheriting configuration from /Users/<omitted_path>/.rubocop.rspec.yml
configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-rspec-2.4.0/config/default.yml
configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-rspec-2.4.0/config/default.yml
Inheriting configuration from /Users/<omitted_path>/.rubocop.rails.yml
configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-rails-2.10.1/config/default.yml
configuration from /Users/test/.gem/ruby/2.7.1/gems/rubocop-rails-2.10.1/config/default.yml
.rubocop.yml: Metrics/ParameterLists:CountKeywordArgs overrides the same parameter in .rubocop.rails.yml
.rubocop.yml: Style/MethodCallWithArgsParentheses:Enabled overrides the same parameter in .rubocop.rails.yml
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.

Please also note that can also opt-in to new cops by default by adding this to your config:
  AllCops:
    NewCops: enable

Lint/EmptyInPattern: # (new in 1.16)
  Enabled: true
Style/InPatternThen: # (new in 1.16)
  Enabled: true
Style/MultilineInPatternThen: # (new in 1.16)
  Enabled: true
Style/QuotedSymbols: # (new in 1.16)
  Enabled: true
RSpec/IdenticalEqualityAssertion: # (new in 2.4)
  Enabled: true
RSpec/Rails/AvoidSetupHook: # (new in 2.4)
  Enabled: true
Rails/EnvironmentVariableAccess: # (new in 2.10)
  Enabled: true
Rails/TimeZoneAssignment: # (new in 2.10)
  Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html
Inspecting 1 file
Scanning /Users/<omitted_path>/test.rb
An error occurred while Layout/HashAlignment cop was inspecting /Users/<omitted_path>/test.rb:3:6.
undefined method `loc' for nil:NilClass
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/layout/hash_alignment.rb:221:in `autocorrect_incompatible_with_other_cops?'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/layout/hash_alignment.rb:206:in `on_hash'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:98:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:69:in `on_hash'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:310:in `inspect_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:281:in `loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:120:in `process_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `reduce'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:47:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:65:in `run_command'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:41:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/exe/rubocop:12:in `block in <top (required)>'
/opt/rubies/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/exe/rubocop:12:in `<top (required)>'
bin/rubocop:29:in `load'
bin/rubocop:29:in `<main>'
An error occurred while Layout/HashAlignment cop was inspecting /Users/test.rb:4:6.
undefined method `loc' for nil:NilClass
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/layout/hash_alignment.rb:221:in `autocorrect_incompatible_with_other_cops?'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/layout/hash_alignment.rb:206:in `on_hash'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:98:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:69:in `on_hash'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:310:in `inspect_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:281:in `loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:120:in `process_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `each'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `reduce'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/runner.rb:47:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:65:in `run_command'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/lib/rubocop/cli.rb:41:in `run'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/exe/rubocop:12:in `block in <top (required)>'
/opt/rubies/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/test/.gem/ruby/2.7.1/gems/rubocop-1.16.1/exe/rubocop:12:in `<top (required)>'
bin/rubocop:29:in `load'
bin/rubocop:29:in `<main>'
.

1 file inspected, no offenses detected

2 errors occurred:
An error occurred while Layout/HashAlignment cop was inspecting /Users/<omitted_path>/test.rb:3:6.
An error occurred while Layout/HashAlignment cop was inspecting /Users/<omitted_path>/test.rb:4:6.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.16.1 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.7.1 x86_64-darwin19)
Finished in 0.63420899999619 seconds

Steps to reproduce the problem

Try to run rubocop on the following test file:

x = { field: 'value1', field2: 'value2' }
hello(**x)
hello({})
def hello(test)
  puts test
end

Run rubocop with provided version

RuboCop version

1.16.1 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.7.1 x86_64-darwin19)
  - rubocop-rails 2.10.1
  - rubocop-rspec 2.4.0
@dvandersluis
Copy link
Member

Please see the pinned issue #9861.

@Achooo
Copy link
Author

Achooo commented Jun 11, 2021

my bad thanks!

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