Class: RuboCop::Cop::StatsD::MetricReturnValue

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

Overview

This Rubocop will check for using the return value of StatsD metric calls, which is deprecated. To check your codebase, use the following Rubocop invocation:

rubocop --require `bundle show statsd-instrument`/lib/statsd/instrument/rubocop.rb \
  --only StatsD/MetricReturnValue

This cop cannot autocorrect offenses. In production code, StatsD should be used in a fire-and-forget fashion. This means that you shouldn't rely on the return value. If you really need to access the emitted metrics, you can look into capture_statsd_calls

Constant Summary collapse

MSG =
"Do not use the return value of StatsD metric methods"
INVALID_PARENTS =
[:lvasgn, :array, :pair, :send, :return, :yield]

Constants included from RuboCop::Cop::StatsD

METAPROGRAMMING_METHODS, METRIC_METHODS, SINGLETON_CONFIGURATION_METHODS

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



24
25
26
27
28
# File 'lib/statsd/instrument/rubocop/metric_return_value.rb', line 24

def on_send(node)
  if metric_method?(node) && node.arguments.last&.type != :block_pass
    add_offense(node.parent) if INVALID_PARENTS.include?(node.parent&.type)
  end
end