Skip to content

Commit

Permalink
Merge pull request #8599 from owst/ignore_multiline_interpolations_in…
Browse files Browse the repository at this point in the history
…_regexps

[Fix #8593] Ignore multi-line interpolations in `Style/RedundantRegexpCharacterClass`
  • Loading branch information
koic committed Aug 26, 2020
2 parents 2d80bf6 + 86c854a commit 999f3dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -31,6 +31,7 @@
* [#8590](https://github.com/rubocop-hq/rubocop/issues/8590): Fix an error when auto-correcting encoding mismatch file. ([@koic][])
* [#8321](https://github.com/rubocop-hq/rubocop/issues/8321): Enable auto-correction for `Layout/{Def}EndAlignment`, `Lint/EmptyEnsure`. ([@marcandre][])
* [#8583](https://github.com/rubocop-hq/rubocop/issues/8583): Fix `Style/RedundantRegexpEscape` false positive for line continuations. ([@owst][])
* [#8593](https://github.com/rubocop-hq/rubocop/issues/8593): Fix `Style/RedundantRegexpCharacterClass` false positive for interpolated multi-line expressions. ([@owst][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/regexp_literal_help.rb
Expand Up @@ -27,7 +27,7 @@ def source_with_comments_and_interpolations_blanked(child, freespace_mode)
# part of the pattern source, but need to preserve their width, to allow offsets to
# correctly line up with the original source: spaces have no effect, and preserve width.
if child.begin_type?
replace_match_with_spaces(source, /.*/) # replace all content
replace_match_with_spaces(source, /.*/m) # replace all content
elsif freespace_mode
replace_match_with_spaces(source, /(?<!\\)#.*/) # replace any comments
else
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/style/redundant_regexp_character_class_spec.rb
Expand Up @@ -224,6 +224,16 @@
end
end

context 'with a multi-line interpolation' do
it 'ignores offenses in the interpolated expression' do
expect_no_offenses(<<~'RUBY')
/#{Regexp.union(
%w"( ) { } [ ] < > $ ! ^ ` ... + * ? ,"
)}/o
RUBY
end
end

context 'with a character class containing a space' do
context 'when not using free-spaced mode' do
it 'registers an offense and corrects' do
Expand Down

0 comments on commit 999f3dd

Please sign in to comment.