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 makes invalid autocorrect with condition on operator #10833

Closed
layerssss opened this issue Jul 24, 2022 · 0 comments · Fixed by #10834
Closed

Style/RedundantCondition makes invalid autocorrect with condition on operator #10833

layerssss opened this issue Jul 24, 2022 · 0 comments · Fixed by #10834
Labels

Comments

@layerssss
Copy link

Style/RedundantCondition makes an autocorrect with -a introducing side-effect for

        seconds = if video_started_at
          timestamp - video_started_at
        else
          timestamp - played_at
        end

autocorrected:

        seconds = (timestamp - video_started_at) || played_at

side-effect introduced: the original code wouldn't raise error when video_started_at is nil. The autocorrected one does raise TypeError: can't convert nil into an exact number


Expected behavior

Rubocop should indicate this can be autocorrected with -A

Actual behavior

Rubocop indicates this can be autocorrected with -a

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.32.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 2.6.6 x86_64-linux)          │~
  - rubocop-rails 2.15.2                                                                       │~
  - rubocop-rspec 2.12.1
@koic koic added the bug label Jul 25, 2022
koic added a commit to koic/rubocop that referenced this issue Jul 25, 2022
…Condition`

Fixes rubocop#10833.

This PR fixes an incorrect autocorrect for `Style/RedundantCondition`
when branches contains arithmetic operation.
bbatsov pushed a commit that referenced this issue Jul 27, 2022
Fixes #10833.

This PR fixes an incorrect autocorrect for `Style/RedundantCondition`
when branches contains arithmetic operation.
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