k0kubun/hamlit

View on GitHub

Showing 84 of 84 total issues

File haml_parser.rb has 626 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ripper'
require 'strscan'

module Hamlit
  class HamlParser
Severity: Major
Found in lib/hamlit/parser/haml_parser.rb - About 1 day to fix

    Class HamlParser has 49 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class HamlParser
        include Hamlit::HamlUtil
    
        attr_reader :root
    
    
    Severity: Minor
    Found in lib/hamlit/parser/haml_parser.rb - About 6 hrs to fix

      Method tag has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
      Open

          def tag(line)
            tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
              nuke_inner_whitespace, action, value, last_line = parse_tag(line.text)
      
            preserve_tag = @options.preserve.include?(tag_name)
      Severity: Minor
      Found in lib/hamlit/parser/haml_parser.rb - About 6 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 call has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          def call(template)
            match = template.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m)
            # discard the last match which is always blank
            match.pop
            @template = match.each_with_index.map do |(full, whitespace, text), index|
      Severity: Minor
      Found in lib/hamlit/parser/haml_parser.rb - About 4 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 parse_tag has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_tag(text)
            match = text.scan(/%([-:\w]+)([-:\w.#\@]*)(.+)?/)[0]
            raise HamlSyntaxError.new(HamlError.message(:invalid_tag, text)) unless match
      
            tag_name, attributes, rest = match
      Severity: Minor
      Found in lib/hamlit/parser/haml_parser.rb - About 4 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 process_line has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_line(line)
            case line.text[0]
            when DIV_CLASS; push div(line)
            when DIV_ID
              return push plain(line) if %w[{ @ $].include?(line.text[1])
      Severity: Minor
      Found in lib/hamlit/parser/haml_parser.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 build_attributes has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

            def build_attributes(is_html, attr_wrapper, escape_attrs, hyphenate_data_attrs, attributes = {})
              # @TODO this is an absolutely ridiculous amount of arguments. At least
              # some of this needs to be moved into an instance method.
              join_char = hyphenate_data_attrs ? '-' : '_'
      
      
      Severity: Minor
      Found in lib/hamlit/parser/haml_attribute_builder.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 haml_tag has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def haml_tag(name, *rest, &block)
            ret = ErrorReturn.new("haml_tag")
      
            text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
            flags = []
      Severity: Minor
      Found in lib/hamlit/parser/haml_helpers.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 parse_new_attribute has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_new_attribute(scanner)
            unless (name = scanner.scan(/[-:\w]+/))
              return if scanner.scan(/\)/)
              return false
            end
      Severity: Minor
      Found in lib/hamlit/parser/haml_parser.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 merge_value has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

            def merge_value(key, to, from)
              if from.kind_of?(Hash) || to.kind_of?(Hash)
                from = { nil => from } if !from.is_a?(Hash)
                to   = { nil => to }   if !to.is_a?(Hash)
                to.merge(from)
      Severity: Minor
      Found in lib/hamlit/parser/haml_attribute_builder.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 tag has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def tag(line)
            tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
              nuke_inner_whitespace, action, value, last_line = parse_tag(line.text)
      
            preserve_tag = @options.preserve.include?(tag_name)
      Severity: Major
      Found in lib/hamlit/parser/haml_parser.rb - About 2 hrs to fix

        Method haml_tag has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def haml_tag(name, *rest, &block)
              ret = ErrorReturn.new("haml_tag")
        
              text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
              flags = []
        Severity: Major
        Found in lib/hamlit/parser/haml_helpers.rb - About 2 hrs to fix

          Method parse_new_attributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_new_attributes(text)
                scanner = StringScanner.new(text)
                last_line = @line.index + 1
                attributes = {}
          
          
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 parse_static_hash has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_static_hash(text)
                attributes = {}
                return attributes if text.empty?
          
                text = text[1...-1] # strip brackets
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 flatten_attributes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

                def flatten_attributes(attributes)
                  flattened = {}
          
                  attributes.each do |key, value|
                    case value
          Severity: Minor
          Found in lib/hamlit/attribute_builder.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 unescape_interpolation has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def unescape_interpolation(str, escape_html = nil)
                res = ''.dup
                rest = Hamlit::HamlUtil.handle_interpolation str.dump do |scan|
                  escapes = (scan[2].size - 1) / 2
                  char = scan[3] # '{', '@' or '$'
          Severity: Minor
          Found in lib/hamlit/parser/haml_util.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 parse_tag has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def parse_tag(text)
                match = text.scan(/%([-:\w]+)([-:\w.#\@]*)(.+)?/)[0]
                raise HamlSyntaxError.new(HamlError.message(:invalid_tag, text)) unless match
          
                tag_name, attributes, rest = match
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.rb - About 1 hr to fix

            Method call has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def call(template)
                  match = template.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m)
                  # discard the last match which is always blank
                  match.pop
                  @template = match.each_with_index.map do |(full, whitespace, text), index|
            Severity: Minor
            Found in lib/hamlit/parser/haml_parser.rb - About 1 hr to fix

              Method silent_script has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def silent_script(line)
                    raise HamlSyntaxError.new(HamlError.message(:no_end), line.index) if line.text[1..-1].strip == 'end'
              
                    line = handle_ruby_multiline(line)
                    keyword = block_keyword(line.text)
              Severity: Minor
              Found in lib/hamlit/parser/haml_parser.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 filter_and_join has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                    def filter_and_join(value, separator)
                      return '' if (value.respond_to?(:empty?) && value.empty?)
              
                      if value.is_a?(Array)
                        value = value.flatten
              Severity: Minor
              Found in lib/hamlit/parser/haml_attribute_builder.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

              Severity
              Category
              Status
              Source
              Language