lib/rubocop/cop/performance/string_include.rb in rubocop-performance-1.19.1 vs lib/rubocop/cop/performance/string_include.rb in rubocop-performance-1.20.0

- old
+ new

@@ -14,21 +14,22 @@ # /ab/.match?(str) # str =~ /ab/ # /ab/ =~ str # str.match(/ab/) # /ab/.match(str) + # /ab/ === str # # # good # str.include?('ab') class StringInclude < Base extend AutoCorrector MSG = 'Use `%<negation>sString#include?` instead of a regex match with literal-only pattern.' - RESTRICT_ON_SEND = %i[match =~ !~ match?].freeze + RESTRICT_ON_SEND = %i[match =~ !~ match? ===].freeze def_node_matcher :redundant_regex?, <<~PATTERN {(call $!nil? {:match :=~ :!~ :match?} (regexp (str $#literal?) (regopt))) - (send (regexp (str $#literal?) (regopt)) {:match :match?} $_) + (send (regexp (str $#literal?) (regopt)) {:match :match? :===} $_) (match-with-lvasgn (regexp (str $#literal?) (regopt)) $_)} PATTERN # rubocop:disable Metrics/AbcSize def on_send(node)