Sha256: 32e74f7a6e8e4119ad8b1c69679270f45ae4fb4bbcd0b91bebe81db4f5f62af7

Contents?: true

Size: 1.18 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
statsd-instrument-3.0.2 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.0.1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.0.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.0.0.pre2 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.9.2 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-3.0.0.pre1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.9.1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.9.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.8.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.7.1 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.7.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb
statsd-instrument-2.6.0 lib/statsd/instrument/rubocop/metric_prefix_argument.rb