File parser.rb
has 722 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'ripper'
require 'strscan'
require 'haml/error'
require 'haml/util'
Class Parser
has 53 methods (exceeds 20 allowed). Consider refactoring. Open
class Parser
include Haml::Util
attr_reader :root
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)
- 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 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
- 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 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
- 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 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])
- 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 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)
- 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 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
- 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 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)
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 = {}
- 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 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
- 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 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
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
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)
- 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 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
- 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 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])
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 = {}
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
- 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 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
- 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 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
- 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 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"
- 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 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
- 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
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)
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
- 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 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
- 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 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|
- 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
Avoid too many return
statements within this method. Open
return push plain(line.strip!(2)) if line.text[1] == SCRIPT
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}}")}}"!]
Avoid too many return
statements within this method. Open
return push haml_comment(line.text[2..-1]) if line.text[1] == SILENT_COMMENT
Avoid too many return
statements within this method. Open
return name, [:static, content.first[1]] if content.size == 1
Avoid too many return
statements within this method. Open
return false unless scanner.scan(re)
Avoid too many return
statements within this method. Open
return push script(line.strip!(2), false) if line.text[1] == SCRIPT
Avoid too many return
statements within this method. Open
return push doctype(line.text) if line.text[0, 3] == '!!!'
Avoid too many return
statements within this method. Open
return unless scanner.scan(/\s*(?:,|$)\s*/)
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] == '#{'
Avoid too many return
statements within this method. Open
return push plain(line.strip!(3), false) if line.text[1, 2] == '=='
Avoid too many return
statements within this method. Open
return push flat_script(line.strip!(2), false) if line.text[1] == FLAT_SCRIPT
Avoid too many return
statements within this method. Open
return name, [:dynamic, var]
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] == '#{'
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?
- 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 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)}
- 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"