Module: RuboCop::Cop::MethodComplexity

Overview

This module handles measurement and reporting of complexity in methods.

Instance Method Summary collapse

Methods included from ConfigurableMax

#max=, #max_parameter_name

Instance Method Details

#on_def(node) ⇒ Object Also known as: on_defs



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 9

def on_def(node)
  max = cop_config['Max']
  complexity = complexity(node)

  return unless complexity > max

  add_offense(node, :keyword, format(self.class::MSG,
                                     node.method_name,
                                     complexity,
                                     max)) do
    self.max = complexity.ceil
  end
end