rubocop-hq/rubocop

View on GitHub
lib/rubocop/cop/style/guard_clause.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
100%

Method register_offense has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
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)
Severity: Minor
Found in lib/rubocop/cop/style/guard_clause.rb - About 45 mins to fix

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

        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
Severity: Minor
Found in lib/rubocop/cop/style/guard_clause.rb - About 45 mins to fix

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_heredoc_argument has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

        def autocorrect_heredoc_argument(corrector, node, heredoc_branch, leave_branch, guard)
Severity: Minor
Found in lib/rubocop/cop/style/guard_clause.rb - About 35 mins to fix

    Method autocorrect has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            def autocorrect(corrector, node, condition, replacement, guard)
    Severity: Minor
    Found in lib/rubocop/cop/style/guard_clause.rb - About 35 mins to fix

      There are no issues that match your filters.

      Category
      Status