sparklemotion/nokogiri

View on GitHub
lib/nokogiri/css/xpath_visitor.rb

Summary

Maintainability
D
1 day
Test Coverage
A
93%

Method visit_function has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

      def visit_function(node)
        msg = :"visit_function_#{node.value.first.gsub(/[(]/, "")}"
        return send(msg, node) if respond_to?(msg)

        case node.value.first
Severity: Minor
Found in lib/nokogiri/css/xpath_visitor.rb - About 3 hrs 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 visit_function has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def visit_function(node)
        msg = :"visit_function_#{node.value.first.gsub(/[(]/, "")}"
        return send(msg, node) if respond_to?(msg)

        case node.value.first
Severity: Major
Found in lib/nokogiri/css/xpath_visitor.rb - About 2 hrs to fix

    File xpath_visitor.rb has 258 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Nokogiri
      module CSS
        # When translating CSS selectors to XPath queries with Nokogiri::CSS.xpath_for, the XPathVisitor
        # class allows for changing some of the behaviors related to builtin xpath functions and quirks
        # of HTML5.
    Severity: Minor
    Found in lib/nokogiri/css/xpath_visitor.rb - About 2 hrs to fix

      Method nth has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def nth(node, options = {})
              unless node.value.size == 4
                raise(ArgumentError, "expected an+b node to contain 4 tokens, but is #{node.value.inspect}")
              end
      
      
      Severity: Minor
      Found in lib/nokogiri/css/xpath_visitor.rb - About 2 hrs 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 visit_element_name has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

            def visit_element_name(node)
              if @doctype == DoctypeConfig::HTML5 && html5_element_name_needs_namespace_handling(node)
                # HTML5 has namespaces that should be ignored in CSS queries
                # https://github.com/sparklemotion/nokogiri/issues/2376
                if @builtins == BuiltinsConfig::ALWAYS || (@builtins == BuiltinsConfig::OPTIMAL && Nokogiri.uses_libxml?)
      Severity: Minor
      Found in lib/nokogiri/css/xpath_visitor.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 visit_attribute_condition has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def visit_attribute_condition(node)
              attribute = node.value.first.accept(self)
              return attribute if node.value.length == 1
      
              value = node.value.last
      Severity: Minor
      Found in lib/nokogiri/css/xpath_visitor.rb - About 1 hr to fix

        Method visit_attribute_condition has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def visit_attribute_condition(node)
                attribute = node.value.first.accept(self)
                return attribute if node.value.length == 1
        
                value = node.value.last
        Severity: Minor
        Found in lib/nokogiri/css/xpath_visitor.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 visit_pseudo_class has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def visit_pseudo_class(node)
                if node.value.first.is_a?(Nokogiri::CSS::Node) && (node.value.first.type == :FUNCTION)
                  node.value.first.accept(self)
                else
                  msg = :"visit_pseudo_class_#{node.value.first.gsub(/[(]/, "")}"
        Severity: Minor
        Found in lib/nokogiri/css/xpath_visitor.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