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

Style/OneLineConditional auto-correct crashes when conditional body contains certain keywords #6751

Closed
patbl opened this issue Feb 10, 2019 · 1 comment
Assignees
Labels

Comments

@patbl
Copy link

patbl commented Feb 10, 2019

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)
@patbl patbl changed the title Style/OneLineConditional auto-correct crashes when conditional body contains retry keyword Style/OneLineConditional auto-correct crashes when conditional body contains certain keywords Feb 10, 2019
@koic koic added the bug label Feb 10, 2019
@Drenmi
Copy link
Collaborator

Drenmi commented Feb 11, 2019

We can fix this by decorating retry nodes with the SendNode a RetryNode node extension. I will open a PR.

Edit: Let's not use SendNode, since retry takes no arguments, and doesn't need the ParameterizedNode extension.

@Drenmi Drenmi self-assigned this Feb 11, 2019
@koic koic closed this as completed in 06fd3db Feb 17, 2019
koic added a commit that referenced this issue Feb 17, 2019
[Fix #6751] Prevent Style/OneLineConditional from breaking on retry and break keywords
@Drenmi Drenmi mentioned this issue Feb 19, 2019
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

3 participants