You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Style/RedundantCondition check can product a false positive when the second part of the ternary condition contains the .. operator. This is because of the order of precedence - in order, it is:
||
..
?:
Since the check replaces ?: with ||, the expression may not evaluate to the same thing as before.
Essentially Ruby is treating this as time_period = (updated_during || 2.days.ago)..Time.now when we want, and think, it to be treating this as time_period = updated_during || (2.days.ago..Time.now).
The best solution to this would seem to be that we should check if the "else branch" is a range and wrap it in parenthesis if it is. I feel like there could be some other similar edge cases, but I can't think of any right now.
The
Style/RedundantCondition
check can product a false positive when the second part of the ternary condition contains the..
operator. This is because of the order of precedence - in order, it is:||
..
?:
Since the check replaces
?:
with||
, the expression may not evaluate to the same thing as before.Expected behavior
No error reported for
Actual behavior
It reports this error:
Autofix will change the expression to
and when
updated_during
is notnil
, the expression will always throw abad range
exception.Steps to reproduce the problem
Enter the code above and run the rubocop on the file.
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:The text was updated successfully, but these errors were encountered: