rubocop-hq/rubocop

View on GitHub
lib/rubocop/cop/metrics/utils/code_length_calculator.rb

Summary

Maintainability
B
5 hrs
Test Coverage
A
100%

Class CodeLengthCalculator has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

        class CodeLengthCalculator
          extend NodePattern::Macros
          include Util

          FOLDABLE_TYPES = %i[array hash heredoc send csend].freeze
Severity: Minor
Found in lib/rubocop/cop/metrics/utils/code_length_calculator.rb - About 2 hrs to fix

    Method code_length has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

              def code_length(node) # rubocop:disable Metrics/MethodLength
                if classlike_node?(node)
                  classlike_code_length(node)
                elsif heredoc_node?(node)
                  heredoc_length(node)
    Severity: Minor
    Found in lib/rubocop/cop/metrics/utils/code_length_calculator.rb - About 55 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 calculate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

              def calculate
                length = code_length(@node)
                return length if @foldable_types.empty?
    
                each_top_level_descendant(@node, @foldable_types) do |descendant|
    Severity: Minor
    Found in lib/rubocop/cop/metrics/utils/code_length_calculator.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 each_top_level_descendant has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

              def each_top_level_descendant(node, types, &block)
                node.each_child_node do |child|
                  next if classlike_node?(child)
    
                  if types.include?(child.type)
    Severity: Minor
    Found in lib/rubocop/cop/metrics/utils/code_length_calculator.rb - About 35 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 source_from_node_with_heredoc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

              def source_from_node_with_heredoc(node)
                last_line = -1
                node.each_descendant do |descendant|
                  next unless descendant.source
    
    
    Severity: Minor
    Found in lib/rubocop/cop/metrics/utils/code_length_calculator.rb - About 35 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

    There are no issues that match your filters.

    Category
    Status