Class: RuboCop::Cop::Alchemrest::TimeTransformWithNoZone
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Alchemrest::TimeTransformWithNoZone
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/rubocop/cop/alchemrest/time_transform_with_no_zone.rb
Constant Summary collapse
- MSG =
<<~MSG Calling `s.from.string.to(Time)` without specifying the timezone is no longer supported BAD: ``` s.from.string.to(Time) ``` GOOD: ``` s.from.string.to(Time).using(:utc) s.from.string.to(Time).using(:local) s.from.string.to(Time).using(ActiveSupport::TimeZone['Mountain Time (US & Canada)']) ``` MSG
Instance Method Summary collapse
Instance Method Details
#build_autocorrection(node) ⇒ Object
48 49 50 51 52 |
# File 'lib/rubocop/cop/alchemrest/time_transform_with_no_zone.rb', line 48 def build_autocorrection(node) <<~CODE.chomp #{node.source}.using(:utc) CODE end |
#on_hash(node) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/alchemrest/time_transform_with_no_zone.rb', line 33 def on_hash(node) node.pairs.each do |pair| transform_node = pair.value next if on_good_time_transform?(transform_node) on_time_transform?(transform_node) do add_offense(transform_node) do |corrector| correction = build_autocorrection(transform_node) corrector.replace(transform_node, correction) if correction end end end end |