Skip to content

Performance/RedundantMatch: False positive #509

@forthrin

Description

@forthrin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions