Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes rubocop#6722. This PR fixes an error for `Style/OneLineConditional` when `then` branch has no body. The following is an error case. ```ruby # example.rb if cond then else dont end ``` The following is a reproduction step. ```console % rubocop -v 0.63.1 % rubocop -a example.rb --only Style/OneLineConditional Inspecting 1 file 0 files inspected, no offenses detected undefined method `type' for nil:NilClass /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:74:in `requires_parentheses?' /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:70:in `expr_replacement' /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.63.1/lib/rubocop/cop/style/one_line_conditional.rb:65:in `to_ternary' (snip) ``` This PR auto-corrected to the following code. ```ruby cond ? nil : dont ``` Actually the above code is the same behavior as `unless` modifier. But this PR aims auto-corrected to an equivalent code without causing an error.
- Loading branch information