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

Rubocop 1.45.0 - Style/RedundantCondition: undefined method `kwsplat_type?' for nil:NilClass #11554

Closed
gnomonunes opened this issue Feb 8, 2023 · 0 comments · Fixed by #11555
Labels

Comments

@gnomonunes
Copy link

gnomonunes commented Feb 8, 2023


Expected behavior

Cop Style/RedundantCondition inspects without breaking.

Actual behavior

Cop Style/RedundantCondition breaks during inspection with the following error:

Scanning condition.rb
An error occurred while Style/RedundantCondition cop was inspecting condition.rb:5:6.
undefined method `kwsplat_type?' for nil:NilClass
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:172:in `argument_with_operator?'
...

Steps to reproduce the problem

  1. Create a file with the following code:
# condition.rb
class Condition
  def setup_user(user)
    Foo.setup do |setup|
      user.present? ? setup.set_user(user) : setup.set_user({})
    end
  end
end
  1. Inspect the code with Style/RedundantCondition cop enabled:
rubocop condition.rb -d

Output:

Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning condition.rb
An error occurred while Style/RedundantCondition cop was inspecting condition.rb:4:6.
undefined method `kwsplat_type?' for nil:NilClass
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:172:in `argument_with_operator?'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:158:in `single_argument_method?'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:151:in `branches_have_method?'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:128:in `synonymous_condition_and_branch?'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:84:in `offense?'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/style/redundant_condition.rb:45:in `on_if'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:105:in `each'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:69:in `on_if'
.rvm/gems/ruby-2.7.2/gems/rubocop-ast-1.24.1/lib/rubocop/ast/traversal.rb:158:in `on_block'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
.rvm/gems/ruby-2.7.2/gems/rubocop-ast-1.24.1/lib/rubocop/ast/traversal.rb:154:in `on_def'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:71:in `on_def'
.rvm/gems/ruby-2.7.2/gems/rubocop-ast-1.24.1/lib/rubocop/ast/traversal.rb:154:in `on_class'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
.rvm/gems/ruby-2.7.2/gems/rubocop-ast-1.24.1/lib/rubocop/ast/traversal.rb:20:in `walk'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cop/team.rb:97:in `investigate'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:345:in `block in inspect_file'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:344:in `each'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:344:in `flat_map'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:344:in `inspect_file'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:314:in `loop'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:163:in `file_offenses'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:154:in `process_file'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:134:in `each'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:134:in `reduce'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:120:in `inspect_files'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/runner.rb:73:in `run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/command.rb:11:in `run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli/environment.rb:18:in `run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli.rb:118:in `run_command'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli.rb:125:in `execute_runners'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli.rb:51:in `block in run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/lib/rubocop/cli.rb:43:in `run'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/exe/rubocop:19:in `block in <top (required)>'
.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
.rvm/gems/ruby-2.7.2/gems/rubocop-1.45.0/exe/rubocop:19:in `<top (required)>'
.rvm/gems/ruby-2.7.2/bin/rubocop:23:in `load'
.rvm/gems/ruby-2.7.2/bin/rubocop:23:in `<main>'
.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `eval'
.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `<main>'

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/RedundantCondition cop was inspecting condition.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.45.0 (using Parser 3.2.0.0, rubocop-ast 1.24.1, running on ruby 2.7.2) [x86_64-darwin21]
Finished in 0.2468809997662902 seconds

RuboCop version

$  bundle exec rubocop -V
1.45.0 (using Parser 3.2.0.0, rubocop-ast 1.24.1, running on ruby 2.7.2) [x86_64-darwin21]
@koic koic added the bug label Feb 8, 2023
koic added a commit to koic/rubocop that referenced this issue Feb 8, 2023
Fixes rubocop#11554.

This PR fixes an error for `Style/RedundantCondition`
when the branches contains empty hash literal argument.
bbatsov pushed a commit that referenced this issue Feb 8, 2023
Fixes #11554.

This PR fixes an error for `Style/RedundantCondition`
when the branches contains empty hash literal argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants