lib/rubocop/cop/style/exact_regexp_match.rb in rubocop-1.51.0 vs lib/rubocop/cop/style/exact_regexp_match.rb in rubocop-1.52.0

- old
+ new

@@ -39,20 +39,26 @@ def on_send(node) return unless (regexp = exact_regexp_match(node)) parsed_regexp = Regexp::Parser.parse(regexp) - tokens = parsed_regexp.map(&:token) - return unless tokens[0] == :bos && tokens[1] == :literal && tokens[2] == :eos + return unless exact_match_pattern?(parsed_regexp) prefer = "#{node.receiver.source} #{new_method(node)} '#{parsed_regexp[1].text}'" add_offense(node, message: format(MSG, prefer: prefer)) do |corrector| corrector.replace(node, prefer) end end private + + def exact_match_pattern?(parsed_regexp) + tokens = parsed_regexp.map(&:token) + return false unless tokens[0] == :bos && tokens[1] == :literal && tokens[2] == :eos + + !parsed_regexp[1].quantifier + end def new_method(node) node.method?(:!~) ? '!=' : '==' end end