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

[Fix #8193] Avoid false positive in Style/RedundantRegexpCharacterClass #8202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
### Bug fixes

* [#8195](https://github.com/rubocop-hq/rubocop/issues/8195): Fix an error for `Style/RedundantFetchBlock` when using `#fetch` with empty block. ([@koic][])
* [#8193](https://github.com/rubocop-hq/rubocop/issues/8193): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using `[\b]`. ([@owst][])

## 0.86.0 (2020-06-22)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_regexp_character_class.rb
Expand Up @@ -34,7 +34,7 @@ class RedundantRegexpCharacterClass < Cop
\[ # Literal [
(?!\#\{) # Not (the start of) an interpolation
(?: # Either...
\\. | # Any escaped character
\\[^b] | # Any escaped character except b (which would change behaviour)
[^.*+?{}()|$] | # or one that doesn't require escaping outside the character class
\\[upP]\{[^}]+\} # or a unicode code-point or property
)
Expand Down
Expand Up @@ -121,6 +121,14 @@
end
end

context 'with a character class containing an escaped-b' do
# See https://github.com/rubocop-hq/rubocop/issues/8193 for details - in short \b != [\b] - the
# former matches a word boundary, the latter a backspace character.
it 'does not register an offense' do
expect_no_offenses('foo = /[\b]/')
end
end

context 'with a character class containing a character requiring escape outside' do
# Not implemented for now, since we would have to escape on auto-correct, and the cop message
# would need to be dynamic to not be misleading.
Expand Down