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

An error occurred while Style/IdenticalConditionalBranches cop was inspecting #9959

Closed
tas50 opened this issue Jul 30, 2021 · 1 comment · Fixed by #9968
Closed

An error occurred while Style/IdenticalConditionalBranches cop was inspecting #9959

tas50 opened this issue Jul 30, 2021 · 1 comment · Fixed by #9968
Labels

Comments

@tas50
Copy link
Contributor

tas50 commented Jul 30, 2021

Expected behavior

RuboCop runs without error

Actual behavior

Inspecting 1 file
Scanning /Users/tsmith/dev/the_world/cerberus/definitions/sentry_json.rb
An error occurred while Style/IdenticalConditionalBranches cop was inspecting /Users/tsmith/dev/the_world/cerberus/definitions/sentry_json.rb:21:13.
Parser::Source::TreeRewriter detected clobbering
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:427:in `trigger_policy'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:414:in `enforce_policy'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:233:in `call'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:233:in `swallow'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:97:in `with'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:124:in `place_in_hierarchy'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:117:in `place_in_hierarchy'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter/action.rb:30:in `combine'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:400:in `combine'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:207:in `wrap'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:243:in `insert_after'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:147:in `block (2 levels) in check_expressions'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/base.rb:342:in `correct'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/base.rb:127:in `add_offense'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:141:in `block in check_expressions'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:140:in `each'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:140:in `check_expressions'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:127:in `check_branches'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/style/identical_conditional_branches.rb:102:in `on_if'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:98:in `each'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:69:in `on_if'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:135:in `on_lvasgn'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:71:in `on_lvasgn'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:137:in `each'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.8.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cop/team.rb:77:in `investigate'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:310:in `inspect_file'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:281:in `loop'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:130:in `block in file_offenses'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:155:in `file_offense_cache'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:129:in `file_offenses'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:120:in `process_file'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `each'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `reduce'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `each_inspected_file'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:86:in `inspect_files'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:47:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/command.rb:11:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli/environment.rb:18:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:65:in `run_command'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:72:in `execute_runners'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:41:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/exe/rubocop:12:in `block in <top (required)>'
/opt/chef-workstation/embedded/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/rubocop-1.18.4/exe/rubocop:12:in `<top (required)>'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/cookstyle-7.15.2/bin/cookstyle:26:in `load'
/opt/chef-workstation/embedded/lib/ruby/gems/3.0.0/gems/cookstyle-7.15.2/bin/cookstyle:26:in `<top (required)>'
/opt/chef-workstation/bin/cookstyle:365:in `load'
/opt/chef-workstation/bin/cookstyle:365:in `<main>'

Steps to reproduce the problem

Scan this file:

define :sentry_json, variables: {}, config_subdir: true do
  conf_dir = params[:jsondir] ? node['firewall']['jsonconf'] : node['firewall']['jsonconf']

  template "#{conf_dir}/#{params[:name]}.json" do
    source 'advancedfw.json.erb'
    variables params[:variables]
    notifies :create, "ruby_block[apply-#{params[:name]}.json]", :delayed
    backup 5
  end
end

RuboCop version

1.18.4 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 3.0.2 x86_64-darwin18)
@koic koic added the bug label Jul 30, 2021
@rrosenblum
Copy link
Contributor

It looks like the issue has to do with the ternary statement. The corrector wasn't designed to account for both of the branches being on the same line.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Aug 2, 2021
bbatsov pushed a commit that referenced this issue Aug 3, 2021
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.

3 participants