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/RedundantRegexpCharacterClass unintentional changes in specific case #8193

Closed
renyamizuno opened this issue Jun 23, 2020 · 3 comments
Closed

Comments

@renyamizuno
Copy link

Style/RedundantRegexpCharacterClass is problematic under in specific case:

def escape(text)
  text.gsub(/.[\b]/, '')
end

# Style/RedundantRegexpCharacterClass: Redundant single-element character class, [\b] can be replaced with \b..

but, \b [\b] behave differently.

https://docs.ruby-lang.org/en/2.7.0/Regexp.html#class-Regexp-label-Anchors

\b - Matches word boundaries when outside brackets; backspace (0x08) when inside brackets


Expected behavior

Ignore [\b] case.

Actual behavior

Change [\b] to \b.

RuboCop version

$ [bundle exec] rubocop -V
0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.0.3, running on ruby 2.7.1 x86_64-darwin18)
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 23, 2020

@owst Can you take a look?

@owst
Copy link
Contributor

owst commented Jun 23, 2020

Aha, I missed this difference in behaviour, apologies - I'll have a look this evening UK time 👍

@koic koic closed this as completed in b417653 Jun 24, 2020
koic added a commit that referenced this issue Jun 24, 2020
…ackslash_b

[Fix #8193] Avoid false positive in Style/RedundantRegexpCharacterClass
@renyamizuno
Copy link
Author

thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants