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 autofixes incorrectly (rubocop 1.29.1) #10636

Closed
delphaber opened this issue May 13, 2022 · 1 comment · Fixed by #10637
Closed

Style/RedundantCondition autofixes incorrectly (rubocop 1.29.1) #10636

delphaber opened this issue May 13, 2022 · 1 comment · Fixed by #10637
Assignees
Labels

Comments

@delphaber
Copy link

This code

class Pippo
  def foo
    result =
      if x
        X.find(x)
      else
        Y.find(y)
      end

    result.to_s
  end
end

generates this warning:

app/pippo.rb:4:7: C: [Correctable] Style/RedundantCondition: Use double pipes || instead.
      if x ...

If I run rubocop -a it gets autofixed with:

class Pippo
  def foo
    result =
      X.find(x || y)

    result.to_s
  end
end

but the behavior now it's changed.

Expected behavior

I think the cop should not raise a warning, because it's not a redundant condition 🤔

RuboCop version

$ bundle exec rubocop -V
 ↳ $ bundle exec rubocop -V
1.29.1 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 2.7.6 x86_64-darwin21)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.14.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.10.0
@koic koic added the bug label May 13, 2022
@dvandersluis dvandersluis self-assigned this May 13, 2022
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue May 13, 2022
…when the branches call the same method on different receivers.
koic added a commit that referenced this issue May 13, 2022
[Fix #10636] Fix false positive in `Style/RedundantCondition` when the branches call the same method on different receivers
@delphaber
Copy link
Author

thank you! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants