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/RedundantCondition can generate syntax errors when safe-auto-correcting #8299

Closed
renatolond opened this issue Jul 10, 2020 · 0 comments · Fixed by #8301
Closed

Style/RedundantCondition can generate syntax errors when safe-auto-correcting #8299

renatolond opened this issue Jul 10, 2020 · 0 comments · Fixed by #8301
Labels

Comments

@renatolond
Copy link

In certain situations, Style/RedundantCondition can generate a syntax errors.


Expected behavior

I'd expect rubocop to either not auto correct (since it was supposed to be a safe auto-correction), or to not generate invalid code.

Actual behavior

rubocop generated code with invalid syntax.

Steps to reproduce the problem

I had a code like this:

def func
  a = 1

  if a
    return a
  else
    raise "Something went wrong"
  end
end

Style/RedundantReturn corrected it to:

def func
  a = 1

  if a
    a
  else
    raise "Something went wrong"
  end
end

Which then Style/RedundantCondition auto corrected to:

def func
  a = 1

  a || raise "Something went wrong"
end

RuboCop version

❯ rubocop -V
0.85.1 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.5.8 x86_64-linux)
@koic koic added the bug label Jul 10, 2020
koic added a commit to koic/rubocop that referenced this issue Jul 14, 2020
…Condition`

Fixes rubocop#8299

This PR fixes an incorrect auto-correct for `Style/RedundantCondition`
when using `raise`, `rescue`, or `and` without argument parentheses in `else`.
bbatsov pushed a commit that referenced this issue Jul 14, 2020
Fixes #8299

This PR fixes an incorrect auto-correct for `Style/RedundantCondition`
when using `raise`, `rescue`, or `and` without argument parentheses in `else`.
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