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

Issue with auto-correct feature and RegEx expressions. #1262

Closed
iamkobold opened this issue Aug 12, 2014 · 3 comments
Closed

Issue with auto-correct feature and RegEx expressions. #1262

iamkobold opened this issue Aug 12, 2014 · 3 comments

Comments

@iamkobold
Copy link

I had the following line of code in ruby that removes numbers and punctuation from a string.

txt = txt.gsub(/[0-9.(),;:!?%#$?\x27\x22_+=\\\/\-]*/, '')

Which RuboCop's auto-correct feature changed it to this.

txt = txt.gsub(/[0-9.(),;:!?%#$CHILD_STATUS\'\"_+=\\\/-]*/, '')

I think that the matching logic was a bit too strong here especially with the $? converted to $CHILD_STATUS which in this context are no where near the same thing.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 13, 2014

There's actually a subtle bug in your code as variable interpolation works in regular expression literals and for global variables like $? you can write only #$? as opposed to #{$?}. You should have also received a warning about the interpolation.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 13, 2014

Hmm, there was a bug indeed - the cop that should have warned you about the interpolation didn't process regexp and backtick literals. This is corrected now.

@iamkobold
Copy link
Author

Thanks @bbatsov I didn't realize RegEx expressions like that were also interpolated.

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

No branches or pull requests

2 participants