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 still making invalid corrections #10607

Closed
miharekar opened this issue May 7, 2022 · 0 comments · Fixed by #10609
Closed

Style/RedundantCondition still making invalid corrections #10607

miharekar opened this issue May 7, 2022 · 0 comments · Fixed by #10609
Labels

Comments

@miharekar
Copy link
Contributor

miharekar commented May 7, 2022

I saw #10605 and the fix in #10606, so I got the latest RuboCop straight from GitHub and my use case still produced the wrong behavior.

Expected behavior

No problem is reported, and autocorrect doesn't break code.

Actual behavior

Offenses:

app/controllers/shots_controller.rb:29:11: C: [Corrected] Style/RedundantCondition: Use double pipes || instead.
    @shot ? redirect_to(@shot) : redirect_to(:root)

RuboCop autocorrection changes the code above to:

@shot || redirect_to(:root)

which in turn breaks the code since in the happy path we don't have redirect anymore.

RuboCop version

❯ bundle exec rubocop -V
1.29.0 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.2 x86_64-darwin21)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.14.2

in Gemfile.lock:

GIT
  remote: https://github.com/rubocop/rubocop.git
  revision: 3531610b1b3f39d4ea39c45271d74e2565cac2b7
  specs:
    rubocop (1.29.0)
      parallel (~> 1.10)
      parser (>= 3.1.0.0)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.8, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.17.0, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 3.0)
nobuyo added a commit to nobuyo/rubocop that referenced this issue May 7, 2022
…en there are parenthesized method calls in each branch
@koic koic added the bug label May 7, 2022
koic added a commit that referenced this issue May 8, 2022
…dant-condition-with-parentheses

[Fix #10607] Fix autocorrect for `Style/RedundantCondition` with parenthesized method call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants