Sha256: 65e692ed8639ca89400f1219a719a6803399b632890b37100502899d84e22050

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 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 `prefix` keyword argument on `StatsD` metric
      # methods and `statsd_*` metaprogramming methods. To run this cop on your codebase:
      #
      #     rubocop --require `bundle show statsd-instrument`/lib/statsd/instrument/rubocop.rb \
      #       --only StatsD/MetricPrefixArgument
      #
      # This cop will not autocorrect offenses.
      class MetricPrefixArgument < Cop
        include RuboCop::Cop::StatsD

        MSG = <<~MSG
          Do not use StatsD.metric(..., prefix: "foo"). The prefix argument is deprecated.

          You can simply include the prefix in the metric name instead.
          If you want to override the global prefix, you can set `no_prefix: true`.
        MSG

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

          if metaprogramming_method?(node)
            add_offense(node) if has_keyword_argument?(node, :prefix)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
statsd-instrument-3.9.2 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.9.1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.9.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.8.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.7.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.6.1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.6.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.5.12 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.5.11 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.5.10 lib/statsd/instrument/rubocop/metric_prefix_argument.rb