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/NegatedIfElseCondition cop error with empty conditional block #8998

Closed
davidenglishmusic opened this issue Nov 5, 2020 · 0 comments · Fixed by #8999
Closed

Style/NegatedIfElseCondition cop error with empty conditional block #8998

davidenglishmusic opened this issue Nov 5, 2020 · 0 comments · Fixed by #8999
Labels

Comments

@davidenglishmusic
Copy link

davidenglishmusic commented Nov 5, 2020

Expected behavior

Not throw an error.

Actual behavior

Throws an error:
An error occurred while Style/NegatedIfElseCondition cop was inspecting example.rb

With debug flag:

Expected a Parser::Source::Range, Comment or Rubocop::AST::Node, got NilClass
/Users/david/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-1.2.0/lib/rubocop/cop/corrector.rb:94:in `to_range'

Steps to reproduce the problem

Run rubocop on the following code ( contrived example ) with the Style/NegatedIfElseCondition cop enabled:

some_val = 1

if !some_val.nil?
else
  some_val = 2
end

RuboCop version

1.2.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.6.6 x86_64-darwin19)
@koic koic added the bug label Nov 6, 2020
koic added a commit to koic/rubocop that referenced this issue Nov 6, 2020
Fixes rubocop#8998.

This PR fixes an error for `Style/NegatedIfElseCondition`
when using negated condition and `if` branch body is empty.
bbatsov pushed a commit that referenced this issue Nov 6, 2020
Fixes #8998.

This PR fixes an error for `Style/NegatedIfElseCondition`
when using negated condition and `if` branch body is empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants