Sha256: d2ea3091227422cd83b4616686d54a4245c9e7cf144c0a1153cdef5fc1d8c549

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rubygems
      # This cop enforces that no outdated deprecations are present on RubyGems
      # code base.
      #
      # @example
      #
      #   As of March, 2019
      #
      #   # bad
      #   deprecate :safdfa, nil, 2018, 12
      #   deprecate :safdfa, nil, 2019, 03
      #
      #   # good
      #   deprecate :safdfa, nil, 2019, 04
      #
      class Deprecations < Cop

        MSG = "Remove `deprecate` calls with dates in the past, along with " \
          "the methods they deprecate, or expand the deprecation horizons to " \
          "a future date"

        def on_send(node)
          _receiver, method_name, *args = *node
          return unless method_name == :deprecate

          scheduled_year = args[2].children.last
          scheduled_month = args[3].children.last

          current_time = Time.now

          current_year = current_time.year
          current_month = current_time.month

          if current_year >= scheduled_year || (current_year == scheduled_year && current_month >= scheduled_month)
            add_offense(node)
          end
        end

        private

        def message(node)
          format(MSG, method: node.method_name)
        end

      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubygems-update-3.1.6 util/cops/deprecations.rb
rubygems-update-3.1.5 util/cops/deprecations.rb
rubygems-update-3.0.9 util/cops/deprecations.rb
rubygems-update-3.1.4 util/cops/deprecations.rb
rubygems-update-3.1.3 util/cops/deprecations.rb
rubygems-update-3.0.8 util/cops/deprecations.rb
rubygems-update-3.0.7 util/cops/deprecations.rb
rubygems-update-3.1.2 util/cops/deprecations.rb
rubygems-update-3.1.1 util/cops/deprecations.rb
rubygems-update-3.1.0 util/cops/deprecations.rb
rubygems-update-3.1.0.pre3 util/cops/deprecations.rb
rubygems-update-3.1.0.pre2 util/cops/deprecations.rb
rubygems-update-3.1.0.pre1 util/cops/deprecations.rb
rubygems-update-3.0.6 util/cops/deprecations.rb
rubygems-update-3.0.5 util/cops/deprecations.rb