Closed
Description
Expected behavior
Running Style/OneLineConditional
on code that contains a conditional with a keyword such as retry
, raise
, or break
in one of its branches with auto-correct enabled doesn't cause Rubocop to crash.
Actual behavior
Running Style/OneLineConditional
on code that contains a conditional with a keyword such as retry
, raise
, or break
in one of its branches with auto-correct enabled causes Rubocop to crash.
Steps to reproduce the problem
This is a problem regardless of whether the keyword occurs in the if
or else
branch.
[21:16:34] ~/Documents ➜ cat foo.rb
if true then retry else 7 end
[21:17:24] ~/Documents ➜ rubocop -a --only Style/OneLineConditional
Inspecting 2 files
0 files inspected, no offenses detected
undefined method `prefix_not?' for s(:retry):RuboCop::AST::Node
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:90:in `keyword_with_changed_precedence?'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:78:in `requires_parentheses?'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:70:in `expr_replacement'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:65:in `to_ternary'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:50:in `replacement'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:39:in `block in autocorrect'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:64:in `block (2 levels) in rewrite'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/parser-2.5.3.0/lib/parser/source/tree_rewriter.rb:220:in `transaction'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:63:in `block in rewrite'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:61:in `each'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/corrector.rb:61:in `rewrite'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:128:in `autocorrect_all_cops'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:72:in `autocorrect'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:100:in `block in offenses'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:117:in `investigate'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:96:in `offenses'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:280:in `inspect_file'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:227:in `block in do_inspection_loop'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:259:in `block in iterate_until_no_changes'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:252:in `loop'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:252:in `iterate_until_no_changes'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:223:in `do_inspection_loop'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:126:in `block in file_offenses'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:144:in `file_offense_cache'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:124:in `file_offenses'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:112:in `process_file'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:89:in `block in each_inspected_file'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `each'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `reduce'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:86:in `each_inspected_file'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:76:in `inspect_files'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/runner.rb:48:in `run'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:174:in `execute_runner'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:75:in `execute_runners'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cli.rb:47:in `run'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/exe/rubocop:13:in `block in <top (required)>'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/pat/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/exe/rubocop:12:in `<top (required)>'
/Users/pat/.rbenv/versions/2.6.0/bin/rubocop:23:in `load'
/Users/pat/.rbenv/versions/2.6.0/bin/rubocop:23:in `<main>'
RuboCop version
[21:17:29] ~/Documents ➜ rubocop -V
0.63.1 (using Parser 2.5.3.0, running on ruby 2.6.0 x86_64-darwin17)
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Style/OneLineConditional auto-correct crashes when conditional body contains `retry` keyword[/-][+]Style/OneLineConditional auto-correct crashes when conditional body contains certain keywords[/+]Drenmi commentedon Feb 11, 2019
We can fix this by decorating
retry
nodes withtheaSendNode
RetryNode
node extension. I will open a PR.Edit: Let's not use
SendNode
, sinceretry
takes no arguments, and doesn't need theParameterizedNode
extension.Merge pull request #6756 from Drenmi/bugfix/retry-node