Skip to content

Commit

Permalink
Merge pull request #2391 from alexdowad/replace_fix
Browse files Browse the repository at this point in the history
[Fix #2390] `Performance/StringReplacement` doesn't convert `gsub(/./, ...)` to `tr`
  • Loading branch information
bbatsov committed Nov 3, 2015
2 parents 63e0be5 + 7f2d271 commit dd4c1ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/string_replacement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Performance
# 'a b c'.delete(' ')
class StringReplacement < Cop
MSG = 'Use `%s` instead of `%s`.'
DETERMINISTIC_REGEX = /^[\w\s\-,."']+$/.freeze
DETERMINISTIC_REGEX = /^[\w\s\-,"']+$/.freeze
REGEXP_CONSTRUCTOR_METHODS = [:new, :compile].freeze
GSUB_METHODS = [:gsub, :gsub!].freeze
DETERMINISTIC_TYPES = [:regexp, :str, :send].freeze
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/performance/string_replacement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@
expect(cop.messages).to be_empty
end

it 'allows regex containing a .' do
inspect_source(cop, %('abc'.gsub(/./, 'a')))

expect(cop.messages).to be_empty
end

it 'allows regex containing a |' do
inspect_source(cop, %('abc'.gsub(/a|b/, 'd')))

Expand Down

0 comments on commit dd4c1ea

Please sign in to comment.