rubocop -a throwing error on a ternary parentheses line

Created on 5 Oct 2016  路  6Comments  路  Source: rubocop-hq/rubocop

Expected behavior

Autocorrect the parentheses style for the below line

m['status'][0] = (i['status'].first == 'open') || (m['status'][0] == 'open') ? 'open' : i['status'].first

Actual behavior

Throws up this backtrace

undefined method `begin' for #<Parser::Source::Map::Operator:0x00000002a7f380>
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/style/ternary_parentheses.rb:72:in `block in autocorrect'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/corrector.rb:57:in `call'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/corrector.rb:57:in `block (2 levels) in rewrite'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/parser-2.3.1.4/lib/parser/source/rewriter.rb:194:in `transaction'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/corrector.rb:56:in `block in rewrite'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/corrector.rb:54:in `each'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/corrector.rb:54:in `rewrite'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:145:in `autocorrect_all_cops'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:77:in `autocorrect'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:105:in `block in offenses'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:122:in `investigate'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:101:in `offenses'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cop/team.rb:52:in `inspect_file'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:244:in `inspect_file'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:191:in `block in do_inspection_loop'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:223:in `block in iterate_until_no_changes'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:216:in `loop'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:216:in `iterate_until_no_changes'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:187:in `do_inspection_loop'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:102:in `block in file_offenses'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:112:in `file_offense_cache'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:100:in `file_offenses'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:91:in `process_file'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:69:in `block in each_inspected_file'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:66:in `each'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:66:in `reduce'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:66:in `each_inspected_file'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:58:in `inspect_files'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/runner.rb:37:in `run'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cli.rb:72:in `execute_runner'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/lib/rubocop/cli.rb:28:in `run'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/bin/rubocop:14:in `block in <top (required)>'
/home/pkp/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/gems/rubocop-0.43.0/bin/rubocop:13:in `<top (required)>'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/bin/rubocop:23:in `load'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/bin/rubocop:23:in `<main>'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/bin/ruby_executable_hooks:15:in `eval'
/home/pkp/.rvm/gems/ruby-2.0.0-p0@incidents/bin/ruby_executable_hooks:15:in `<main>'

Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

RuboCop version

$ rubocop -V
0.43.0 (using Parser 2.3.1.4, running on ruby 2.0.0 x86_64-linux)

Most helpful comment

I can confirm that this has been fixed on master. Here are some test cases I added which pass as expected without any errors.

All 6 comments

Here's a minimal case which will trigger the same issue:
(cond1) || (cond2) ? 1 : 2

I would like to try and solve this if someone could point me in the right direction :)

Actually, it looks like this has already been solved on master. :smiley_cat:

I think this fixes it.

I can confirm that this has been fixed on master. Here are some test cases I added which pass as expected without any errors.

@pramodhkp, don't forget to close this. :stuck_out_tongue:

Closing because fix already present.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deivid-rodriguez picture deivid-rodriguez  路  3Comments

lepieru picture lepieru  路  3Comments

millisami picture millisami  路  3Comments

herwinw picture herwinw  路  3Comments

NobodysNightmare picture NobodysNightmare  路  3Comments