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
Add autocorrection to Lint/EmptyConditionalBody
#10862
Add autocorrection to Lint/EmptyConditionalBody
#10862
Conversation
89cd694
to
7045023
Compare
343f417
to
8e0bdc6
Compare
8e0bdc6
to
05b7f70
Compare
elsif another_condition | ||
do_something_else | ||
end | ||
RUBY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dvandersluis this correction doesn't have the same semantics. To get the same meaning, it should be:
if !condition && other_condition
do_something
elsif !condition && another_condition
do_something_else
end
I don't know if this autocorrection was considered safe before, but it definitely isn't safe or correct now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I noticed this after it was merged, and it's been changed to SafeAutoCorrect: false
. I haven't had a chance to look at fixing the autocorrection yet so feel free to create a PR!
x = if bar | ||
5 | ||
end | ||
RUBY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, this should be:
x = if !foo && bar
5
end
I noticed in #10858 (comment) that
Lint/EmptyConditionalBody
does not have autocorrection, so I added it. It does the following:AllowComments
is false.elsif
toif
andelse
toif
/unless
appropriately, if the topmost branch is the one being removed.if
statement being preceded by another node.I believe I've covered the edge cases here but if there's one you can think of let me know and I'll add it in. I also was unsure if we should mark this as
SafeAutoCorrect: false
but am happy to do so.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.