Sha256: 86e29a7be68becc65246bd0449635fd93d60351fe253f346b67ed6d8efcfa82d
Contents?: true
Size: 825 Bytes
Versions: 30
Compression:
Stored size: 825 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Discourse # Use `Time.zone.now` instead of `Time.new` without arguments. # # @example # # bad # now = Time.new # # # good # now = Time.zone.now class NoTimeNewWithoutArgs < Cop MSG = "Use `Time.zone.now` instead of `Time.new` without arguments." def_node_matcher :time_new_without_args?, <<-MATCHER (send (const nil? :Time) :new) MATCHER def on_send(node) return unless time_new_without_args?(node) add_offense(node, message: MSG) end def autocorrect(node) lambda do |corrector| corrector.replace(node.loc.expression, "Time.zone.now") end end end end end end
Version data entries
30 entries across 30 versions & 1 rubygems