Sha256: 6078bdcb19a535872f250d7c3fdb952f0827d47b508d8c6299f05cd0510ec53f

Contents?: true

Size: 1.18 KB

Versions: 17

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

17 entries across 17 versions & 1 rubygems

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