Skip to content

Commit

Permalink
Merge pull request #8202 from owst/allow_character_class_containing_b…
Browse files Browse the repository at this point in the history
…ackslash_b

[Fix #8193] Avoid false positive in Style/RedundantRegexpCharacterClass
  • Loading branch information
koic committed Jun 24, 2020
2 parents a62e992 + b417653 commit 4cb9e49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,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

0 comments on commit 4cb9e49

Please sign in to comment.