Sha256: 56f8d4d45fe34073d27de99b72b4e0bb57e00d6106c37b0c774e6f35b6e3d0c6

Contents?: true

Size: 1.25 KB

Versions: 17

Compression:

Stored size: 1.25 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 providing the value for a metric using a keyword argument, which is
      # deprecated. Use the following Rubocop invocation to check your project's codebase:
      #
      #    rubocop --require \
      #      `bundle show statsd-instrument`/lib/statsd/instrument/rubocop.rb \
      #      --only StatsD/MetricValueKeywordArgument
      #
      # This cop will not autocorrect offenses. Most of the time, these are easy to fix by providing the
      # value as the second argument, rather than a keyword argument.
      #
      # `StatsD.increment('foo', value: 3)` => `StatsD.increment('foo', 3)`
      class MetricValueKeywordArgument < Cop
        include RuboCop::Cop::StatsD

        MSG = <<~MSG
          Do not use the StatsD.metric('name', value: <value>, ...). The `value` keyword argument is deprecated.

          Use a positional argument instead: StatsD.metric('name', <value>, ...).
        MSG

        def on_send(node)
          if metric_method?(node) && has_keyword_argument?(node, :value)
            add_offense(node)
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
statsd-instrument-3.5.9 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.8 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.7 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.6 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.5 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.4 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.3 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.2 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.1 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.5.0 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.4.0 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.3.0 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.2.1 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.2.0 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.1.2 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.1.1 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb
statsd-instrument-3.1.0 lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb