Fix RSpec/MatchWithSimpleRegex to ignore match nested inside include matchers#2195
Open
ydah wants to merge 1 commit into
Open
Fix RSpec/MatchWithSimpleRegex to ignore match nested inside include matchers#2195ydah wants to merge 1 commit into
RSpec/MatchWithSimpleRegex to ignore match nested inside include matchers#2195ydah wants to merge 1 commit into
Conversation
RSpec/MatchWithSimpleRegex to ignore match nested inside include matchers
3c10218 to
0286913
Compare
0286913 to
ae8f7a8
Compare
bquorning
reviewed
Jun 23, 2026
| 'without a parent node' do | ||
| expect_offense(<<~RUBY) | ||
| match(/foo/) | ||
| ^^^^^^^^^^^^ Prefer using `include('foo')` when the regex is a simple string literal. |
Collaborator
There was a problem hiding this comment.
This is wrong behavior, right? We should only match inside examples I think.
It's not something you added by the way. The cop was implemented wrong (by me) from the beginning.
ae8f7a8 to
cde547c
Compare
bquorning
reviewed
Jun 23, 2026
| 'include matcher' do | ||
| expect_no_offenses(<<~RUBY) | ||
| expect(errors).to include(match(/message/)) | ||
| expect(errors).to include(match(/message/), match(/warning/)) |
Collaborator
There was a problem hiding this comment.
What is a valid use case for an example like this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
RSpec/MatchWithSimpleRegexto ignorematchwhen it is already nested insideincludematcher arguments.Before this change,
include(match(/message/))was detected and autocorrected toinclude(include('message')). The nestedincludeform is valid matcher composition, but it is not clearer than the original expression and goes against the cop's purpose.This keeps the direct
expect(body).to match(/message/)correction, while leaving nestedinclude(match(...))unchanged.Before submitting the PR make sure the following are checked:
master(if not - rebase it).CHANGELOG.mdif the new code introduces user-observable changes.bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).