Class: HamlLint::Tree::RootNode
- Defined in:
- lib/haml_lint/tree/root_node.rb
Overview
Represents the root node of a HAML document that contains all other nodes.
Instance Attribute Summary
Attributes inherited from Node
#children, #line, #parent, #type
Instance Method Summary collapse
-
#file ⇒ String
The name fo the file parsed to build this tree.
-
#node_for_line(line) ⇒ HamlLint::Node
Gets the node of the syntax tree for a given line number.
Methods inherited from Node
#comment_configuration, #directives, #disabled?, #each, #initialize, #inspect, #keyword, #line_numbers, #lines, #next_node, #predecessor, #source_code, #subsequents, #successor, #text
Constructor Details
This class inherits a constructor from HamlLint::Tree::Node
Instance Method Details
#file ⇒ String
The name fo the file parsed to build this tree.
11 12 13 |
# File 'lib/haml_lint/tree/root_node.rb', line 11 def file @document.file end |
#node_for_line(line) ⇒ HamlLint::Node
Gets the node of the syntax tree for a given line number.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/haml_lint/tree/root_node.rb', line 19 def node_for_line(line) # rubocop:disable Metrics each do |node| return node if node.line_numbers.cover?(line) && node != self end # Because HAML doesn't leave any trace in the nodes when it merges lines that # end with a comma, it's harder to assign a node to the second line here: # = some_call user, # foo, bar # So if the simple strategy (above) doesn't work, we try to see if we check if the last node # that was before the requested line was one that could have been merged. If so, we use that one. best_guess = nil each do |node| best_guess = node if node != self && node.line_numbers.end < line end # There are the cases were the merging without traces can happen return best_guess if best_guess && %i[script silent_script tag].include?(best_guess.type) HamlLint::Tree::NullNode.new end |