Sha256: 6cf86e0ac897da8dcea44687e2291f6280415a50d847781d23d422996ccdf4fb

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require_relative "../rubocop" unless defined?(RuboCop::Cop::StatsD)

module RuboCop
  module Cop
    module StatsD
      # This Rubocop will check for specifying the `as_dist: true` keyword argument on `StatsD.measure`
      # and `statsd_measure`. This argument is deprecated. Instead, you can use `StatsD.distribution`
      # (or `statsd_distribution`) directly.
      #
      # To run this cop on your codebase:
      #
      #     rubocop --require `bundle show statsd-instrument`/lib/statsd/instrument/rubocop.rb \
      #       --only StatsD/MeasureAsDistArgument
      #
      # This cop will not autocorrect offenses.
      class MeasureAsDistArgument < Base
        include RuboCop::Cop::StatsD

        MSG = <<~MSG
          Do not use StatsD.measure(..., as_dist: true). This is deprecated.

          Use StatsD.distribution (or statsd_distribution) instead.
        MSG

        def on_send(node)
          if metric_method?(node) && node.method_name == :measure
            add_offense(node) if has_keyword_argument?(node, :as_dist)
          end

          if metaprogramming_method?(node) && node.method_name == :statsd_measure
            add_offense(node) if has_keyword_argument?(node, :as_dist)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
statsd-instrument-3.9.9 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.8 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.7 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.6 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.5 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.4 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb
statsd-instrument-3.9.3 lib/statsd/instrument/rubocop/measure_as_dist_argument.rb