Class: Sass::Tree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/scss_lint/sass/tree.rb

Overview

Define some common helper code for use in the various monkey patchings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#node_parentObject

Stores node for which this node is a direct child



12
13
14
# File 'lib/scss_lint/sass/tree.rb', line 12

def node_parent
  @node_parent
end

Instance Method Details

#add_line_number(node) ⇒ Object

The Sass parser sometimes doesn’t assign line numbers in cases where it should. This is a helper to easily correct that.



16
17
18
19
# File 'lib/scss_lint/sass/tree.rb', line 16

def add_line_number(node)
  node.line ||= line if node.is_a?(::Sass::Script::Tree::Node)
  node
end

#concat_expr_lists(*expr_lists) ⇒ Object

Takes a list of arguments, be they arrays or individual objects, and returns a single flat list that can be passed to Sass::Tree::Visitors::Base#visit_children.



40
41
42
# File 'lib/scss_lint/sass/tree.rb', line 40

def concat_expr_lists(*expr_lists)
  expr_lists.flatten.compact
end

#create_variable(var_name) ⇒ Object

Sometimes the parse tree doesn’t return a Sass::Script::Variable, but just the name of the variable. This helper takes that name and turns it back into a Sass::Script::Variable that supports lint reporting.



24
25
26
27
28
# File 'lib/scss_lint/sass/tree.rb', line 24

def create_variable(var_name)
  ::Sass::Script::Tree::Variable.new(var_name).tap do |v|
    v.line = line # Use line number of the containing parse tree node
  end
end

#extract_script_nodes(list) ⇒ Object

A number of tree nodes return lists that have strings and Sass::Script::Nodes interspersed within them. This returns a filtered list of just those nodes.



33
34
35
# File 'lib/scss_lint/sass/tree.rb', line 33

def extract_script_nodes(list)
  list.select { |item| item.is_a?(::Sass::Script::Tree::Node) }
end