lib/rubocop/cop/performance/string_include.rb in rubocop-performance-1.8.1 vs lib/rubocop/cop/performance/string_include.rb in rubocop-performance-1.9.0
- old
+ new
@@ -21,10 +21,11 @@
# 'abc'.include?('ab')
class StringInclude < Base
extend AutoCorrector
MSG = 'Use `String#include?` instead of a regex match with literal-only pattern.'
+ RESTRICT_ON_SEND = %i[match =~ match?].freeze
def_node_matcher :redundant_regex?, <<~PATTERN
{(send $!nil? {:match :=~ :match?} (regexp (str $#literal?) (regopt)))
(send (regexp (str $#literal?) (regopt)) {:match :match?} $str)
(match-with-lvasgn (regexp (str $#literal?) (regopt)) $_)}
@@ -45,10 +46,10 @@
alias on_match_with_lvasgn on_send
private
def literal?(regex_str)
- regex_str.match?(/\A#{Util::LITERAL_REGEX}+\z/)
+ regex_str.match?(/\A#{Util::LITERAL_REGEX}+\z/o)
end
end
end
end
end