lib/rubocop/cop/performance/delete_suffix.rb in rubocop-performance-1.18.0 vs lib/rubocop/cop/performance/delete_suffix.rb in rubocop-performance-1.19.0

- old
+ new

@@ -62,13 +62,14 @@ sub: :delete_suffix, sub!: :delete_suffix! }.freeze def_node_matcher :delete_suffix_candidate?, <<~PATTERN - (send $!nil? ${:gsub :gsub! :sub :sub!} (regexp (str $#literal_at_end?) (regopt)) (str $_)) + (call $!nil? ${:gsub :gsub! :sub :sub!} (regexp (str $#literal_at_end?) (regopt)) (str $_)) PATTERN + # rubocop:disable Metrics/AbcSize def on_send(node) return unless (receiver, bad_method, regexp_str, replace_string = delete_suffix_candidate?(node)) return unless replace_string.empty? good_method = PREFERRED_METHODS[bad_method] @@ -78,14 +79,16 @@ add_offense(node.loc.selector, message: message) do |corrector| regexp_str = drop_end_metacharacter(regexp_str) regexp_str = interpret_string_escapes(regexp_str) string_literal = to_string_literal(regexp_str) - new_code = "#{receiver.source}.#{good_method}(#{string_literal})" + new_code = "#{receiver.source}#{node.loc.dot.source}#{good_method}(#{string_literal})" corrector.replace(node, new_code) end end + # rubocop:enable Metrics/AbcSize + alias on_csend on_send end end end end