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 --auto-correct raises undefined method error. #3922

Closed
tmtm opened this issue Jan 17, 2017 · 0 comments
Closed

rubocop --auto-correct raises undefined method error. #3922

tmtm opened this issue Jan 17, 2017 · 0 comments
Labels

Comments

@tmtm
Copy link
Contributor

tmtm commented Jan 17, 2017

Expected behavior

Don't raise error.

Actual behavior

rubocop raises undefined method error.

Steps to reproduce the problem

% cat sample.rb 
!str.empty? ? 123 : 456
% rubocop sample.rb 
Inspecting 1 file
C

Offenses:

sample.rb:1:1: C: Favor  over  for negative conditions.
!str.empty? ? 123 : 456
^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
% rubocop --auto-correct sample.rb
Inspecting 1 file


0 files inspected, no offenses detected
undefined method `keyword' for #<Parser::Source::Map::Ternary:0x000000025d4a10>
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/mixin/negative_conditional.rb:30:in `block in negative_conditional_corrector'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/corrector.rb:56:in `block (2 levels) in rewrite'
/tmp/gem/gems/parser-2.3.3.1/lib/parser/source/rewriter.rb:194:in `transaction'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/corrector.rb:55:in `block in rewrite'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/corrector.rb:53:in `each'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/corrector.rb:53:in `rewrite'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:140:in `autocorrect_all_cops'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:77:in `autocorrect'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:105:in `block in offenses'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:122:in `investigate'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:101:in `offenses'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cop/team.rb:51:in `inspect_file'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:248:in `inspect_file'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:195:in `block in do_inspection_loop'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:227:in `block in iterate_until_no_changes'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:220:in `loop'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:220:in `iterate_until_no_changes'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:191:in `do_inspection_loop'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:101:in `block in file_offenses'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:111:in `file_offense_cache'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:99:in `file_offenses'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:90:in `process_file'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:65:in `each'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:65:in `reduce'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:65:in `each_inspected_file'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:57:in `inspect_files'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/runner.rb:36:in `run'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cli.rb:72:in `execute_runner'
/tmp/gem/gems/rubocop-0.47.0/lib/rubocop/cli.rb:27:in `run'
/tmp/gem/gems/rubocop-0.47.0/bin/rubocop:13:in `block in <top (required)>'
/usr/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/tmp/gem/gems/rubocop-0.47.0/bin/rubocop:12:in `<top (required)>'
/tmp/gem/bin/rubocop:23:in `load'
/tmp/gem/bin/rubocop:23:in `<main>'

RuboCop version

0.47.0 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-linux-gnu)
@bbatsov bbatsov added the bug label Jan 17, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue Jan 17, 2017
… ternary

This cop would blow up on a negated ternary condition. Since ternaries
don't have an `unless` equivalent, this was fixed by just returning
early for ternary nodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants