Skip to content

Conversation

@Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Aug 11, 2025

Fix #14435

It does expressions = expressions.to_a, which does not create a copy. So other cops that run after would not see all
the expressions.

.dup would solve this, but all this does is work around a bug in regexp_parser < 2.7.0. RuboCop now requires >= 2.9.3 so all that code can simply be removed.

I didn't add a new test because the code that would be tested is gone now.

Also see #13875 for something quite similar.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@Earlopain Earlopain force-pushed the regexp-expression-modification branch from ee74513 to 87206b7 Compare August 11, 2025 10:02
@Earlopain
Copy link
Contributor Author

I froze the expressions to check if there are other cops that modify them but that doesn't seem to be the case now. Can't commit that though, since one of the monkey-patches for them does @foo ||= "bar"-style memoization which doesn't work once frozen.

@Earlopain Earlopain force-pushed the regexp-expression-modification branch from 87206b7 to dd069ef Compare August 11, 2025 13:46
@Earlopain Earlopain changed the title [Fix #14435] Fix false negaitves for regexp cops when Lint/DuplicateRegexpCharacterClassElement is enabled [Fix #14435] Fix false negatives for regexp cops when Lint/DuplicateRegexpCharacterClassElement is enabled Aug 11, 2025
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 12, 2025

@Earlopain Shouldn't we add some tests covering the false negatives that were fixed?

I didn't add a new test because the code that would be tested is gone now.

I find this part confusing. :D

…plicateRegexpCharacterClassElement` is enabled

It does `expressions = expressions.to_a`, which does not create a copy. So other cops
that run after would not see all
the expressions.

`.dup` would solve this, but all this does is work around a bug in `regexp_parser` < 2.7.0.
RuboCop now requires >= 2.9.3 so all that code can simply be removed.

I didn't add a new test because the code that would be tested is gone now.

Also see rubocop#13875 for something quite similar.
@Earlopain Earlopain force-pushed the regexp-expression-modification branch from dd069ef to 32815b4 Compare August 12, 2025 08:45
@Earlopain
Copy link
Contributor Author

I find this part confusing. :D

There was a PR that accidentally introduced regexp ast modifications and I basically reverted that since it's no longer necessary. Anyways, I added a test

@bbatsov bbatsov merged commit b776d32 into rubocop:master Aug 12, 2025
23 checks passed
@Earlopain Earlopain deleted the regexp-expression-modification branch September 3, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Style/RedundantRegexpEscape not run when NewCops: enable

2 participants