From 770b91ee617286ba7344e98205786f809283b385 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Tue, 29 Sep 2020 00:11:46 +0100 Subject: [PATCH] Add test for #8805 --- .../cop/style/redundant_regexp_escape_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/rubocop/cop/style/redundant_regexp_escape_spec.rb b/spec/rubocop/cop/style/redundant_regexp_escape_spec.rb index 21d093d0f6b..f081d983ded 100644 --- a/spec/rubocop/cop/style/redundant_regexp_escape_spec.rb +++ b/spec/rubocop/cop/style/redundant_regexp_escape_spec.rb @@ -442,6 +442,19 @@ end end + context 'with a # inside a character class' do + it 'does not register an offense' do + # See https://github.com/rubocop-hq/rubocop/issues/8805 - the # inside the character class + # must not be treated as starting a comment (which makes the following \. redundant) + expect_no_offenses(<<~'RUBY') + regexp = %r{ + \A[a-z#] # letters or # + \.[a-z]\z # dot + letters + }x + RUBY + end + end + context 'with redundantly-escaped slashes' do it 'registers an offense and corrects' do expect_offense(<<~'RUBY')