Class: RuboCop::Cop::Rails::ToFormattedS
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::ToFormattedS
- Extended by:
- AutoCorrector, TargetRailsVersion
- Includes:
- ConfigurableEnforcedStyle
- Defined in:
- lib/rubocop/cop/rails/to_formatted_s.rb
Overview
Checks for consistent uses of ‘to_fs` or `to_formatted_s`, depending on the cop’s configuration.
Constant Summary collapse
- MSG =
'Use `%<prefer>s` instead.'
- RESTRICT_ON_SEND =
%i[to_formatted_s to_fs].freeze
Constants included from TargetRailsVersion
TargetRailsVersion::TARGET_GEM_NAME, TargetRailsVersion::USES_REQUIRES_GEM_API
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Methods included from TargetRailsVersion
minimum_target_rails_version, support_target_rails_version?
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
35 36 37 38 39 40 41 |
# File 'lib/rubocop/cop/rails/to_formatted_s.rb', line 35 def on_send(node) return if node.method?(style) add_offense(node.loc.selector, message: format(MSG, prefer: style)) do |corrector| corrector.replace(node.loc.selector, style) end end |