Class: RuboCop::Cop::StatsD::MetricPrefixArgument

Inherits:
Base
  • Object
show all
Includes:
RuboCop::Cop::StatsD
Defined in:
lib/statsd/instrument/rubocop/metric_prefix_argument.rb

Overview

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.

Constant Summary collapse

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

Constants included from RuboCop::Cop::StatsD

METAPROGRAMMING_METHODS, METRIC_METHODS, SINGLETON_CONFIGURATION_METHODS

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/statsd/instrument/rubocop/metric_prefix_argument.rb', line 25

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