File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55- Fix false positives for ` RSpec/SpecFilePathFormat ` when matching spec partials. ([ @ydah ] )
66- Fix incorrect autocorrection for ` RSpec/DescribedClass ` when using nested example groups with ` EnforcedStyle: explicit ` . ([ @ydah ] )
7+ - Fix ` RSpec/MatchWithSimpleRegex ` to ignore ` match ` nested inside ` include ` matchers. ([ @ydah ] )
78
89## 3.10.2 (2026-06-06)
910
Original file line number Diff line number Diff line change @@ -38,7 +38,14 @@ class MatchWithSimpleRegex < Base
3838 (send nil? :match $regexp)
3939 PATTERN
4040
41+ # @!method include_matcher_argument?(node)
42+ def_node_matcher :include_matcher_argument? , <<~PATTERN
43+ ^(send nil? :include ...)
44+ PATTERN
45+
4146 def on_send ( node )
47+ return if include_matcher_argument? ( node )
48+
4249 match_with_regexp? ( node ) do |regexp |
4350 next unless simple_regexp? ( regexp )
4451
Original file line number Diff line number Diff line change 1212 RUBY
1313 end
1414
15+ it 'registers an offense when using match with simple string regex ' \
16+ 'without a parent node' do
17+ expect_offense ( <<~RUBY )
18+ match(/foo/)
19+ ^^^^^^^^^^^^ Prefer using `include('foo')` when the regex is a simple string literal.
20+ RUBY
21+
22+ expect_correction ( <<~RUBY )
23+ include('foo')
24+ RUBY
25+ end
26+
1527 it 'registers an offense when using match with escaped URL regex' do
1628 expect_offense ( <<~'RUBY' )
1729 expect(response.body).to match(/http:\/\/example\.com/)
4860 RUBY
4961 end
5062
63+ it 'does not register an offense when using match within an ' \
64+ 'include matcher' do
65+ expect_no_offenses ( <<~RUBY )
66+ expect(errors).to include(match(/message/))
67+ expect(errors).to include(match(/message/), match(/warning/))
68+ RUBY
69+ end
70+
5171 it 'does not register an offense when using match with anchor at start' do
5272 expect_no_offenses ( <<~RUBY )
5373 expect('foobar').to match(/^foo/)
You can’t perform that action at this time.
0 commit comments