Sha256: 83ec04a47343024e51387d7c15714247b511a7ed1a02149563d72ab64d8b2c1e
Contents?: true
Size: 801 Bytes
Versions: 10
Compression:
Stored size: 801 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 < Base 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 { |corrector| corrector.replace(node.loc.expression, "Time.zone.now") } end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems