rubocop-performance icon indicating copy to clipboard operation
rubocop-performance copied to clipboard

Performance/RedundantMatch: False positive

Open forthrin opened this issue 6 months ago • 2 comments

Steps to reproduce the problem

puts 'fox'.match(/(f)/) ? $1 : ''

puts $1 if 'cat'.match(/(c)/)

'rabbit'.match(/(r)/)
puts $1

exit unless 'squirrel'.match(/(s)/)
puts $1

Expected behavior

MatchData is successfully used in all examples, so should not get patted down by officer.

Actual behavior

4 x [Correctable] Performance/RedundantMatch: Use =~ in places where the MatchData returned by #match will not be used.

RuboCop version

ruby      2025-08-01 30a20bc16
rubocop   2025-10-18 f7f653f50
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1

forthrin avatar Aug 11 '25 05:08 forthrin

Bömp! Still very much an issue. Just forgot it was disabled in .rubocop.yml pending resolution.

forthrin avatar Oct 18 '25 08:10 forthrin

@5-hun: Thanks for looking into this one. What's holding #523 back from merging with master?

forthrin avatar Dec 11 '25 09:12 forthrin