rubocop-performance
rubocop-performance copied to clipboard
Performance/RegexpMatch: Wording pitfall will negate code expression
Steps to reproduce the problem
puts 1 if foo !~ /fo./
Actual behavior
Use `match?` instead of `!~` when `MatchData` is not used. [[Correctable] Performance/RegexpMatch]
Pitfall: Changing the code according to the exact wording will actually negate the expression.
Expected behavior
A correct rewording would be something like:
- Use
!match?instead of!~when ... - Use
match?instead of!~and negate the expression when ... - Use
match?instead of!~and replace if with unless when ...
RuboCop version
rubocop-performance (1.25.0)
ruby 2025-08-01 30a20bc16
rubocop 2025-08-11 c595cf6e2
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1