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
Fixesrubocop#5467.
This PR fixes a false negative for `Style/MultipleComparison` when
multiple comparison is not part of a conditional.
The following is a false negative example of issue.
```ruby
def foo(x)
x == 1 || x == 2 || x == 3
end
```
In addition, this PR will change the offense range as follows.
```diff
a = "a"
if a == "a" || a == "b"
- ^^^^^^^^^^^^^^^^^^^^^^^ Avoid comparing a variable with multiple
items in a conditional, use `Array#include?` instead.
+ ^^^^^^^^^^^^^^^^^^^^ Avoid comparing a variable with multiple
items in a conditional, use `Array#include?` instead.
print a
end
```
Since `if` statements are not subject to replace with `Array#include?`,
this change will result in a strict offense range.
Fixes#5467.
This PR fixes a false negative for `Style/MultipleComparison` when
multiple comparison is not part of a conditional.
The following is a false negative example of issue.
```ruby
def foo(x)
x == 1 || x == 2 || x == 3
end
```
In addition, this PR will change the offense range as follows.
```diff
a = "a"
if a == "a" || a == "b"
- ^^^^^^^^^^^^^^^^^^^^^^^ Avoid comparing a variable with multiple
items in a conditional, use `Array#include?` instead.
+ ^^^^^^^^^^^^^^^^^^^^ Avoid comparing a variable with multiple
items in a conditional, use `Array#include?` instead.
print a
end
```
Since `if` statements are not subject to replace with `Array#include?`,
this change will result in a strict offense range.
The
Style/MultipleComparison
cop fails to trigger if the multiple comparison is not part of a conditional.Expected behavior
A Style/MultipleComparison violation is triggered for
as this could be written more succinctly as
Actual behavior
No Style/MultipleComparison violation is reported.
Steps to reproduce the problem
$ cat bug.rb
def foo(x)
x == 1 || x == 2 || x == 3
end
$ bundle exec rubocop --only Style/MultipleComparison bug.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
RuboCop version
The text was updated successfully, but these errors were encountered: