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.
Class ChunkExtractor
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
class ChunkExtractor
include HamlLint::HamlVisitor
attr_reader :script_output_prefix
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 '$'
- Read upRead up
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)
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
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 '$'
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
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)
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)
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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'
- Read upRead up
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
- Read upRead up
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/] == '#'
- Read upRead up
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"