Class: RuboCop::Cop::Rails::ToSWithArgument

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetRailsVersion
Defined in:
lib/rubocop/cop/rails/to_s_with_argument.rb

Overview

Identifies passing any argument to `#to_s`.

Examples:


# bad
obj.to_s(:delimited)

# good
obj.to_formatted_s(:delimited)

Constant Summary collapse

MSG =
'Use `to_formatted_s` instead.'
RESTRICT_ON_SEND =
%i[to_s].freeze

Instance Method Summary collapse

Methods included from TargetRailsVersion

minimum_target_rails_version, support_target_rails_version?

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



30
31
32
33
34
35
36
# File 'lib/rubocop/cop/rails/to_s_with_argument.rb', line 30

def on_send(node)
  return if node.arguments.empty?

  add_offense(node.loc.selector) do |corrector|
    corrector.replace(node.loc.selector, 'to_formatted_s')
  end
end