class Sass::Tree::Node

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

Attributes

node_parent[RW]

Stores node for which this node is a direct child

Public Instance Methods

add_line_number(node) click to toggle source

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

# 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) click to toggle source

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.

# File lib/scss_lint/sass/tree.rb, line 40
def concat_expr_lists(*expr_lists)
  expr_lists.flatten.compact
end
create_variable(var_name) click to toggle source

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.

# 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) click to toggle source

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.

# 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