Class: RuboCop::Cop::RailsDeprecation::ToFormattedS

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rails_deprecation/to_formatted_s.rb

Overview

This cop identifies passing a format to ‘#to_s`.

Examples:


# bad
to_s(:delimited)

# good
to_fs(:delimited)

# good
to_formatted_s(:delimited)

# good
to_s

Constant Summary collapse

MSG =
'Use `to_fs(...)` instead of `to_s(...)`.'

Constants inherited from Base

Base::DEFAULT_MAXIMUM_TARGET_RAILS_VERSION, Base::DEFAULT_MINIMUM_TARGET_RAILS_VERSION

Instance Method Summary collapse

Methods inherited from Base

support_target_rails_version?

Instance Method Details

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



36
37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/rails_deprecation/to_formatted_s.rb', line 36

def on_send(node)
  return unless to_s_with_any_argument?(node)

  add_offense(node) do |rewriter|
    rewriter.replace(
      node.loc.selector,
      'to_fs'
    )
  end
end