-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
to_formatted_s.rb
45 lines (40 loc) · 1.06 KB
/
to_formatted_s.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# This cop checks for consistent uses of `to_fs` or `to_formatted_s`,
# depending on the cop's configuration.
#
# @example EnforcedStyle: to_fs (default)
#
# # bad
# time.to_formatted_s(:db)
#
# # good
# time.to_fs(:db)
#
# @example EnforcedStyle: to_formatted_s
#
# # bad
# time.to_fs(:db)
#
# # good
# time.to_formatted_s(:db)
#
class ToFormattedS < Base
include ConfigurableEnforcedStyle
extend AutoCorrector
extend TargetRailsVersion
minimum_target_rails_version 7.0
MSG = 'Use `%<prefer>s` instead.'
RESTRICT_ON_SEND = %i[to_formatted_s to_fs].freeze
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
end
end
end
end