lib/rubocop/cop/style/guard_clause.rb
Method register_offense
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def register_offense(node, scope_exiting_keyword, conditional_keyword, guard = nil)
condition, = node.node_parts
example = [scope_exiting_keyword, conditional_keyword, condition.source].join(' ')
if too_long_for_single_line?(node, example)
return if trivial?(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 autocorrect
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def autocorrect(corrector, node, condition, replacement, guard)
corrector.replace(node.loc.keyword.join(condition.source_range), replacement)
if_branch = node.if_branch
else_branch = node.else_branch
- 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 autocorrect
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def autocorrect(corrector, node, condition, replacement, guard)
Method autocorrect_heredoc_argument
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def autocorrect_heredoc_argument(corrector, node, heredoc_branch, leave_branch, guard)