-
-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Description
I've noticed that the cop's autocorrection is incorrect when using operators with lower precedence than =~ as an argument to match.
Here's the reproducible code:
arg = nil
puts "pass" if /regex/.match(arg || "default")Expected behavior
To preserve the original behavior, parentheses should be added around the RHS.
arg = nil
puts "pass" if /regex/ =~ (arg || "default")This code produces no output.
Actual behavior
Parentheses are missing, which results in the condition being evaluated as (/regex/ =~ arg) || "default".
arg = nil
puts "pass" if /regex/ =~ arg || "default"This code outputs "pass".
Steps to reproduce the problem
- Save the provided code snippet into a file named
example.rb. - Execute
bundle exec rubocop --only Performance/RedundantMatch -a example.rb.
RuboCop version
$ bundle exec rubocop -V
1.56.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.0.2) [
x86_64-linux]
- rubocop-performance 1.19.0
- rubocop-rspec 2.22.0
Metadata
Metadata
Assignees
Labels
No labels