rubocop-hq/rubocop

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

Summary

Maintainability
B
6 hrs
Test Coverage
A
100%

Class SafeNavigation has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

      class SafeNavigation < Base
        include NilMethods
        include RangeHelp
        extend AutoCorrector
        extend TargetRubyVersion
Severity: Minor
Found in lib/rubocop/cop/style/safe_navigation.rb - About 2 hrs to fix

    Method unsafe_method_used? has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            def unsafe_method_used?(method_chain, method)
              return true if unsafe_method?(method)
    
              method.each_ancestor(:send).any? do |ancestor|
                break true unless config.for_cop('Lint/SafeNavigationChain')['Enabled']
    Severity: Minor
    Found in lib/rubocop/cop/style/safe_navigation.rb - About 1 hr 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 add_safe_nav_to_all_methods_in_chain has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

            def add_safe_nav_to_all_methods_in_chain(corrector,
                                                     start_method,
                                                     method_chain)
              start_method.each_ancestor do |ancestor|
                break unless %i[send block].include?(ancestor.type)
    Severity: Minor
    Found in lib/rubocop/cop/style/safe_navigation.rb - About 1 hr 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

    Avoid too many return statements within this method.
    Open

              return if method_chain.method?(:empty?)
    Severity: Major
    Found in lib/rubocop/cop/style/safe_navigation.rb - About 30 mins to fix

      Method check_node has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def check_node(node)
                checked_variable, receiver, method_chain, method = extract_parts(node)
                return if receiver != checked_variable || receiver.nil?
                return if use_var_only_in_unless_modifier?(node, checked_variable)
                return if chain_length(method_chain, method) > max_chain_length
      Severity: Minor
      Found in lib/rubocop/cop/style/safe_navigation.rb - About 25 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