Module: RuboCop::Cop::MethodComplexity Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::RuboCop::ExcludeLimit ,
Macros
|
|
Instance Chain:
|
|
Defined in: | lib/rubocop/cop/mixin/method_complexity.rb |
Overview
This module handles measurement and reporting of complexity in methods.
Class Method Summary
::RuboCop::ExcludeLimit
- Extended
exclude_limit | Sets up a configuration option to have an exclude limit tracked. |
transform |
Instance Attribute Summary
AllowedPattern
- Included
AllowedMethods
- Included
Instance Method Summary
- #on_block(node) (also: #on_numblock) Internal use only
- #on_def(node) (also: #on_defs) Internal use only
-
#on_defs(node)
Alias for #on_def.
-
#on_numblock(node)
Alias for #on_block.
- #check_complexity(node, method_name) private Internal use only
- #complexity(body) private Internal use only
- #define_method?(node) private
- #location(node) private Internal use only
Metrics::Utils::RepeatedCsendDiscount
- Included
AllowedPattern
- Included
#allowed_line?, #allowed_patterns, #cop_config_deprecated_methods_values, #cop_config_patterns_values, #matches_allowed_pattern? |
AllowedMethods
- Included
Instance Method Details
#check_complexity(node, method_name) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 42
def check_complexity(node, method_name) # Accepts empty methods always. return unless node.body max = cop_config['Max'] reset_repeated_csend complexity, abc_vector = complexity(node.body) return unless complexity > max msg = format( self.class::MSG, method: method_name, complexity: complexity, abc_vector: abc_vector, max: max ) location = location(node) add_offense(location, message: msg) { self.max = complexity.ceil } end
#complexity(body) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 61
def complexity(body) score = 1 body.each_node(:lvasgn, *self.class::COUNTED_NODES) do |node| if node.lvasgn_type? reset_on_lvasgn(node) else score += complexity_score_for(node) end end score end
#define_method?(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 37
def_node_matcher :define_method?, <<~PATTERN ({block numblock} (send nil? :define_method ({sym str} $_)) _ _) PATTERN
#location(node) (private)
[ GitHub ]#on_block(node) Also known as: #on_numblock
[ GitHub ]# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 24
def on_block(node) define_method?(node) do |name| return if allowed_method?(name) || matches_allowed_pattern?(name) check_complexity(node, name) end end
#on_def(node) Also known as: #on_defs
[ GitHub ]# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 17
def on_def(node) return if allowed_method?(node.method_name) || matches_allowed_pattern?(node.method_name) check_complexity(node, node.method_name) end
#on_defs(node)
Alias for #on_def.
# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 22
alias on_defs on_def
#on_numblock(node)
Alias for #on_block.
# File 'lib/rubocop/cop/mixin/method_complexity.rb', line 32
alias on_numblock on_block