Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect fix suggestion for Style/RedundantRegexpCharacterClass #10530

Closed
patrickdavey opened this issue Apr 12, 2022 · 0 comments · Fixed by #10531
Closed

Incorrect fix suggestion for Style/RedundantRegexpCharacterClass #10530

patrickdavey opened this issue Apr 12, 2022 · 0 comments · Fixed by #10531
Labels

Comments

@patrickdavey
Copy link

I have a string where I am trying to replace some unicode chars and rubocop is saying that it's a redundant single-element character class when I don't believe it is.

In this example I am going to try to replace all a and b (unicode 0061 0062) with the letter F

 s = "aaabbbccc"
 s.gsub(/[\u{0061 0062}]/, "F") 
# this correctly outputs "FFFFFFccc" which is correct.

Rubocop however suggests I should remove the square brackets with :

Style/RedundantRegexpCharacterClass: Redundant single-element character class, `[\u{0061 0062}]` can be replaced with `\u{0061 0062}`

However, if you remove the braces you get an incorrect value

 s = "aaabbbccc"
 s.gsub(/\u{0061 0062}/, "F") 
# this incorrectly outputs "aaFbbccc" which is incorrect.

Expected behavior

/[\u{0061 0062}]/

should not suggest Style/RedundantRegexpCharacterClass

Actual behavior

/[\u{0061 0062}]/

does suggest Style/RedundantRegexpCharacterClass

Steps to reproduce the problem

  1. create the line s = /[\u{0061 0062}]/ in a ruby file, expect no violations.

RuboCop version

1.27.0

@koic koic added the bug label Apr 12, 2022
koic added a commit to koic/rubocop that referenced this issue Apr 12, 2022
…aracterClass`

Fixes rubocop#10530.

This PR fixes a false positive for `Style/RedundantRegexpCharacterClass`
when using regexp character class with a character class containing
multiple unicode code-points.
bbatsov pushed a commit that referenced this issue Apr 14, 2022
…Class`

Fixes #10530.

This PR fixes a false positive for `Style/RedundantRegexpCharacterClass`
when using regexp character class with a character class containing
multiple unicode code-points.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants