class Sass::Tree::Node
Define some common helper code for use in the various monkey patchings.
Attributes
Stores node for which this node is a direct child
Public Instance Methods
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
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
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
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