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

Autocorrection bug in Style/RedundantConditional cop #4676

Closed
pocke opened this issue Aug 24, 2017 · 1 comment
Closed

Autocorrection bug in Style/RedundantConditional cop #4676

pocke opened this issue Aug 24, 2017 · 1 comment
Labels

Comments

@pocke
Copy link
Collaborator

pocke commented Aug 24, 2017

If "bad" code has elsif, Style/RedundantConditional generates wrong code when autocorrect.

if cond
  foo
elsif x == y
  true
else
  false
end

Expected behavior

Autocorrection generates the following code.

if cond
  foo
else
  x == y
end

Actual behavior

Autocorrection generates the following code actually.

if cond
  foo
  x == y
end

Steps to reproduce the problem

  1. Put the above code as test.rb
  2. Run rubocop -a

RuboCop version

master(ce6483c)

@pocke pocke added the bug label Aug 24, 2017
@Drenmi
Copy link
Collaborator

Drenmi commented Aug 27, 2017

Good catch! I can see this happening with how parser nests the AST for elsifs.

akhramov pushed a commit to akhramov/rubocop that referenced this issue Aug 31, 2017
Current implementation of `Style/RedundantConditional` cop doesn't
handle the case when RedundantConditional occured in the elsif node. As
a result, autocorrection fails.

This commit tweaks the cop so it handles the elsif nodes as well.
@bbatsov bbatsov closed this as completed in ded79d2 Sep 1, 2017
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

2 participants