lib/haml/parser.rb

Summary

Maintainability
F
1 wk
Test Coverage
A
99%

File parser.rb has 722 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ripper'
require 'strscan'
require 'haml/error'
require 'haml/util'

Severity: Major
Found in lib/haml/parser.rb - About 1 day to fix

    Class Parser has 53 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Parser
        include Haml::Util
    
        attr_reader :root
    
    
    Severity: Major
    Found in lib/haml/parser.rb - About 7 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/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 35 (exceeds 5 allowed). Consider refactoring.
      Open

          def call(template)
            template = Haml::Util.check_haml_encoding(template) do |msg, line|
              raise Haml::Error.new(msg, line)
            end
      
      
      Severity: Minor
      Found in lib/haml/parser.rb - About 5 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 SyntaxError.new(Error.message(:invalid_tag, text)) unless match
      
            tag_name, attributes, rest = match
      Severity: Minor
      Found in lib/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/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 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/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 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/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 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/haml/parser.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/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/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_tag has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

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

              def call(template)
                template = Haml::Util.check_haml_encoding(template) do |msg, line|
                  raise Haml::Error.new(msg, line)
                end
          
          
          Severity: Minor
          Found in lib/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 SyntaxError.new(Error.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/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 handle_multiline has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def handle_multiline(line)
                  return unless is_multiline?(line.text)
                  line.text.slice!(-1)
                  loop do
                    new_line = @template.first
            Severity: Minor
            Found in lib/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 process_line has 34 lines of code (exceeds 25 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/haml/parser.rb - About 1 hr to fix

              Method parse_new_attributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def parse_new_attributes(text)
                    scanner = StringScanner.new(text)
                    last_line = @line.index + 1
                    attributes = {}
              
              
              Severity: Minor
              Found in lib/haml/parser.rb - About 1 hr to fix

                Method filter_and_join has a Cognitive Complexity of 11 (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/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 compute_tabs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    def compute_tabs(line)
                      return 0 if line.text.empty? || !line.whitespace
                
                      if @indentation.nil?
                        @indentation = line.whitespace
                Severity: Minor
                Found in lib/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 next_line has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    def next_line
                      line = @template.shift || raise(StopIteration)
                
                      # `flat?' here is a little outdated,
                      # so we have to manually check if either the previous or current line
                Severity: Minor
                Found in lib/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 close_silent_script has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def close_silent_script(node)
                      @script_level_stack.pop if ["if", "case", "unless"].include? node.value[:keyword]
                
                      # Post-process case statements to normalize the nesting of "when" clauses
                      return unless node.value[:keyword] == "case"
                Severity: Minor
                Found in lib/haml/parser.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 handle_ruby_multiline has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def handle_ruby_multiline(line)
                      line.text.rstrip!
                      return line unless is_ruby_multiline?(line.text)
                      begin
                        # Use already fetched @next_line in the first loop. Otherwise, fetch next
                Severity: Minor
                Found in lib/haml/parser.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

                Consider simplifying this complex logical expression.
                Open

                      unless (flat? && !closes_flat?(line) && !closes_flat?(@line)) ||
                          (line_defined && @line.text[0] == ?: && line.full =~ %r[^#{@line.full[/^\s+/]}\s])
                        return next_line if line.text.empty?
                
                        handle_multiline(line)
                Severity: Major
                Found in lib/haml/parser.rb - About 40 mins to fix

                  Method comment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def comment(text)
                        if text[0..1] == '!['
                          revealed = true
                          text = text[1..-1]
                        else
                  Severity: Minor
                  Found in lib/haml/parser.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 plain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def plain(line, escape_html = nil)
                        if block_opened?
                          raise SyntaxError.new(Error.message(:illegal_nesting_plain), @next_line.index)
                        end
                  
                  
                  Severity: Minor
                  Found in lib/haml/parser.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 parse_class_and_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def self.parse_class_and_id(list)
                        attributes = {}
                        return attributes if list.empty?
                  
                        list.scan(/([#.])([-:_a-zA-Z0-9\@]+)/) do |type, property|
                  Severity: Minor
                  Found in lib/haml/parser.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

                  Avoid too many return statements within this method.
                  Open

                          return push plain(line.strip!(2)) if line.text[1] == SCRIPT
                  Severity: Major
                  Found in lib/haml/parser.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                          return name, [:dynamic,
                            %!"#{content.each_with_object(''.dup) {|(t, v), s| s << (t == :str ? Util.inspect_obj(v)[1...-1] : "\#{#{v}}")}}"!]
                    Severity: Major
                    Found in lib/haml/parser.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return push haml_comment(line.text[2..-1]) if line.text[1] == SILENT_COMMENT
                      Severity: Major
                      Found in lib/haml/parser.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                              return name, [:static, content.first[1]] if content.size == 1
                        Severity: Major
                        Found in lib/haml/parser.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return false unless scanner.scan(re)
                          Severity: Major
                          Found in lib/haml/parser.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return push script(line.strip!(2), false) if line.text[1] == SCRIPT
                            Severity: Major
                            Found in lib/haml/parser.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return push doctype(line.text) if line.text[0, 3] == '!!!'
                              Severity: Major
                              Found in lib/haml/parser.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return unless scanner.scan(/\s*(?:,|$)\s*/)
                                Severity: Major
                                Found in lib/haml/parser.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return push plain(line.strip!(1), :escape_html) if line.text[1] == ?\s || line.text[1..2] == '#{'
                                  Severity: Major
                                  Found in lib/haml/parser.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return push plain(line.strip!(3), false) if line.text[1, 2] == '=='
                                    Severity: Major
                                    Found in lib/haml/parser.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return push flat_script(line.strip!(2), false) if line.text[1] == FLAT_SCRIPT
                                      Severity: Major
                                      Found in lib/haml/parser.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return name, [:dynamic, var]
                                        Severity: Major
                                        Found in lib/haml/parser.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return push plain(line.strip!(1), false) if line.text[1] == ?\s || line.text[1..2] == '#{'
                                          Severity: Major
                                          Found in lib/haml/parser.rb - About 30 mins to fix

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

                                                def haml_comment(text)
                                                  if filter_opened?
                                                    @flat = true
                                                    @filter_buffer = String.new
                                                    @filter_buffer << "#{text}\n" unless text.empty?
                                            Severity: Minor
                                            Found in lib/haml/parser.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 process_indent has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                def process_indent(line)
                                                  return unless line.tabs <= @template_tabs && @template_tabs > 0
                                            
                                                  to_close = @template_tabs - line.tabs
                                                  to_close.times {|i| close unless to_close - 1 - i == 0 && continuation_script?(line.text)}
                                            Severity: Minor
                                            Found in lib/haml/parser.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