Method register_offense
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def register_offense(node, message, replacement) # rubocop:disable Metrics/AbcSize
add_offense(node.value, message: message) do |corrector|
corrector.replace(node, replacement)
next unless (def_node = def_node_that_require_parentheses(node))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method def_node_that_require_parentheses
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def def_node_that_require_parentheses(node)
last_pair = node.parent.pairs.last
return unless last_pair.key.source == last_pair.value.source
return unless (dispatch_node = find_ancestor_method_dispatch_node(node))
return if dispatch_node.assignment_method?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method on_pair
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def on_pair(node)
return if ignore_hash_shorthand_syntax?(node)
hash_key_source = node.key.source
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return if dispatch_node.parent && parentheses?(dispatch_node.parent)
Avoid too many return
statements within this method. Open
return if last_expression?(dispatch_node) && !method_dispatch_as_argument?(dispatch_node)
Method find_ancestor_method_dispatch_node
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def find_ancestor_method_dispatch_node(node)
return unless (ancestor = node.parent.parent)
return unless ancestor.call_type? || ancestor.super_type? || ancestor.yield_type?
return if brackets?(ancestor)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"