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
Closed
Labels
bug

Comments

@renatolond
Copy link

@renatolond renatolond commented Jul 10, 2020

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 10, 2020
…antCondition`

Fixes rubocop-hq#8299

This PR fixes an incorrect auto-correct for `Style/RedundantCondition`
when using `raise` without argument parentheses in `else`.
koic added a commit to koic/rubocop that referenced this issue Jul 14, 2020
…antCondition`

Fixes rubocop-hq#8299

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

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.