Skip to content

Commit d5de6b2

Browse files
committed
Consider regexp with options a non-simple regexp
1 parent ec3eeab commit d5de6b2

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
- Fix `RSpec/MatchWithSimpleRegex` to ignore regular expressions with options. ([@bquorning])
6+
57
## 3.10.1 (2026-06-05)
68

79
- Add `Strict` option to `RSpec/SharedContext` to flag `shared_context` whenever it contains examples, even alongside setup code. ([@Darhazer])

lib/rubocop/cop/rspec/match_with_simple_regex.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def on_send(node)
5555

5656
def simple_regexp?(node)
5757
return false if node.interpolation?
58+
return false if node.regopt.children.any?
5859

5960
parsed = Regexp::Parser.parse(node.content)
6061
parsed.expressions.all? { |expr| simple_expression?(expr) }

spec/rubocop/cop/rspec/match_with_simple_regex_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@
9090
RUBY
9191
end
9292

93+
it 'does not register an offense when using match with regex options' do
94+
expect_no_offenses(<<~RUBY)
95+
expect('foobar').to match(/foo/x)
96+
expect('foobar').to match(/foo/i)
97+
expect('foobar').to match(/foo/m)
98+
expect('foobar').to match(/foo/n)
99+
expect('foobar').to match(/foo/u)
100+
expect('foobar').to match(/foo/o)
101+
RUBY
102+
end
103+
93104
it 'does not register an offense when using match with string ' \
94105
'instead of regex' do
95106
expect_no_offenses(<<~RUBY)

0 commit comments

Comments
 (0)