Rubocop: Style/RedundantRegexpCharacterClass unintentional changes in specific case

Created on 23 Jun 2020  路  3Comments  路  Source: rubocop-hq/rubocop

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)
bug weird ruby

Most helpful comment

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

All 3 comments

@owst Can you take a look?

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

thx!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bquorning picture bquorning  路  3Comments

lepieru picture lepieru  路  3Comments

bbatsov picture bbatsov  路  3Comments

Aqualon picture Aqualon  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments