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

Style/RedundantRegexpEscape should register and offence for escaped hypens in character groups when a hypen is the first/last character #11150

Closed
Earlopain opened this issue Nov 3, 2022 · 0 comments · Fixed by #11152
Labels

Comments

@Earlopain
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Consider the following regexes:

unescaped1 = /[0-9-]/
escaped1   = /[0-9\-]/

unescaped2 = /[-0-9]/
escaped2   = /[\-0-9]/

All 4 match numbers 0 through 9 and -. It is not neccesary to escape - when it is the first or last character in the group since there is no ambiguity about it. Either the user mistyped or it is intended like this. Regardless of that, the backslash is redundant.

Describe the solution you'd like

Rubocop should register an offence for escaped hypens in character groups when the hypen is either the first or last character.

@koic koic added the bug label Nov 4, 2022
si-lens added a commit to si-lens/rubocop that referenced this issue Nov 12, 2022
Catch redundant regexp escape when the escaped hyphen is the first or the last character within the character class.
bbatsov pushed a commit that referenced this issue Nov 12, 2022
Catch redundant regexp escape when the escaped hyphen is the first or the last character within the character class.
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