sds/haml-lint

View on GitHub
lib/haml_lint/ruby_extraction/chunk_extractor.rb

Summary

Maintainability
D
2 days
Test Coverage

File chunk_extractor.rb has 414 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module HamlLint::RubyExtraction
  # Extracts "chunks" of the haml file into instances of subclasses of HamlLint::RubyExtraction::BaseChunk.
  #
  # This is the first step of generating Ruby code from a HAML file to then be processed by RuboCop.
  # See HamlLint::RubyExtraction::BaseChunk for more details.
Severity: Minor
Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 5 hrs to fix

    Class ChunkExtractor has 28 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class ChunkExtractor
        include HamlLint::HamlVisitor
    
        attr_reader :script_output_prefix
    
    
    Severity: Minor
    Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 3 hrs to fix

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

          def add_interpolation_chunks(node, code, haml_line_index, indent:, line_start_index: 0)
            HamlLint::Utils.handle_interpolation_with_indexes(code) do |scanner, line_index, line_char_index|
              escapes = scanner[2].size
              next if escapes.odd?
              char = scanner[3] # '{', '@' or '$'
      Severity: Minor
      Found in lib/haml_lint/ruby_extraction/chunk_extractor.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 extract_raw_ruby_lines has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def extract_raw_ruby_lines(haml_processed_ruby_code, first_line_index)
            haml_processed_ruby_code = haml_processed_ruby_code.strip
            first_line = @original_haml_lines[first_line_index]
      
            char_index = first_line.index(haml_processed_ruby_code)
      Severity: Minor
      Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 1 hr to fix

        Method visit_script has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def visit_script(node, &block)
              raw_first_line = @original_haml_lines[node.line - 1]
        
              # ==, !, !==, &, &== means interpolation (was needed before HAML 2.2... it's still supported)
              # =, !=, &= mean actual ruby code is coming
        Severity: Minor
        Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 1 hr to fix

          Method add_interpolation_chunks has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def add_interpolation_chunks(node, code, haml_line_index, indent:, line_start_index: 0)
                HamlLint::Utils.handle_interpolation_with_indexes(code) do |scanner, line_index, line_char_index|
                  escapes = scanner[2].size
                  next if escapes.odd?
                  char = scanner[3] # '{', '@' or '$'
          Severity: Minor
          Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 1 hr to fix

            Method visit_tag_attributes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def visit_tag_attributes(node, indent:)
                  final_line_index = node.line - 1
                  additional_attributes = node.dynamic_attributes_sources
            
                  attributes_code = additional_attributes.first
            Severity: Minor
            Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 1 hr to fix

              Method extract_raw_tag_attributes_ruby_lines has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def extract_raw_tag_attributes_ruby_lines(haml_processed_ruby_code, first_line_index)
                    haml_processed_ruby_code = haml_processed_ruby_code.strip
                    first_line = @original_haml_lines[first_line_index]
              
                    char_index = first_line.index(haml_processed_ruby_code)
              Severity: Minor
              Found in lib/haml_lint/ruby_extraction/chunk_extractor.rb - About 1 hr to fix

                Method finish_visit_any_script has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def finish_visit_any_script(node, lines, raw_code: nil, must_start_chunk: false, first_output_prefix: '=')
                      raw_code ||= lines.join("\n")
                      start_nesting = self.class.start_nesting_after?(raw_code)
                
                      lines = add_following_empty_lines(node, lines)
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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 extract_raw_ruby_lines has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def extract_raw_ruby_lines(haml_processed_ruby_code, first_line_index)
                      haml_processed_ruby_code = haml_processed_ruby_code.strip
                      first_line = @original_haml_lines[first_line_index]
                
                      char_index = first_line.index(haml_processed_ruby_code)
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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_tag_attributes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def visit_tag_attributes(node, indent:)
                      final_line_index = node.line - 1
                      additional_attributes = node.dynamic_attributes_sources
                
                      attributes_code = additional_attributes.first
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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_filter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def visit_filter(node)
                      # For unknown reasons, haml doesn't escape interpolations in filters.
                      # So we can rely on \n to split / get the number of lines.
                      filter_name_indent = @original_haml_lines[node.line - 1].index(/\S/)
                      if node.filter_type == 'ruby'
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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 visit_script has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def visit_script(node, &block)
                      raw_first_line = @original_haml_lines[node.line - 1]
                
                      # ==, !, !==, &, &== means interpolation (was needed before HAML 2.2... it's still supported)
                      # =, !=, &= mean actual ruby code is coming
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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 visit_tag_script has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def visit_tag_script(node, line_index:, indent:)
                      return if node.script.nil? || node.script.empty?
                      # We ignore scripts which are just a comment
                      return if node.script[/\S/] == '#'
                
                
                Severity: Minor
                Found in lib/haml_lint/ruby_extraction/chunk_extractor.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