haml/html2haml

View on GitHub
lib/html2haml/html.rb

Summary

Maintainability
F
3 days
Test Coverage

Method to_haml has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
Open

      def to_haml(tabs, options)
        return "" if converted_to_haml

        if name == "script" &&
            (attr_hash['type'].nil? || attr_hash['type'].to_s == "text/javascript") &&
Severity: Minor
Found in lib/html2haml/html.rb - About 1 day 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

File html.rb has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'cgi'
require 'nokogiri'
require 'html2haml/html/erb'

# Haml monkeypatches various Nokogiri classes
Severity: Minor
Found in lib/html2haml/html.rb - About 5 hrs to fix

    Method to_haml has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def to_haml(tabs, options)
            return "" if converted_to_haml
    
            if name == "script" &&
                (attr_hash['type'].nil? || attr_hash['type'].to_s == "text/javascript") &&
    Severity: Major
    Found in lib/html2haml/html.rb - About 3 hrs to fix

      Method to_haml has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def to_haml(tabs, options)
              attrs = external_id.nil? ? ["", "", ""] :
                external_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
              raise Haml::SyntaxError.new("Invalid doctype") if attrs == nil
      
      
      Severity: Minor
      Found in lib/html2haml/html.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 dynamic_attributes has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def dynamic_attributes
              #reject any attrs without <haml>
              @dynamic_attributes = attr_hash.select {|name, value| value =~ %r{<haml.*</haml} }
              @dynamic_attributes.each do |name, value|
                fragment = Nokogiri::XML.fragment(CGI.unescapeHTML(value))
      Severity: Minor
      Found in lib/html2haml/html.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 output + " " + text.lstrip.gsub(/^\\/, '') unless text.chomp.include?("\n") || text.empty?
      Severity: Major
      Found in lib/html2haml/html.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return render_children("", tabs, options)
        Severity: Major
        Found in lib/html2haml/html.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                        return output + "\n" + text
          Severity: Major
          Found in lib/html2haml/html.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return output + child.to_haml(tabs + 1, options).lstrip
            Severity: Major
            Found in lib/html2haml/html.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return CGI.unescapeHTML(inner_text).split("\n").map do |line|
                            next "" if line.strip.empty?
                            "#{output}- #{line.strip}\n"
                          end.join
              Severity: Major
              Found in lib/html2haml/html.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                              return output + "\n#{tabulate(tabs + 1)}:preserve\n" +
                                inner_text.gsub(/^/, tabulate(tabs + 2))
                Severity: Major
                Found in lib/html2haml/html.rb - About 30 mins to fix

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

                      def initialize(template, options = {})
                        @options = options
                  
                        if template.is_a? Nokogiri::XML::Node
                          @template = template
                  Severity: Minor
                  Found in lib/html2haml/html.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

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

                        def to_haml_filter(filter, tabs, options)
                          content =
                            if children.first && children.first.cdata?
                              decode_entities(children.first.content_without_cdata_tokens)
                            else
                  Severity: Minor
                  Found in lib/html2haml/html.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