lib/scss_lint/utils.rb in scss-lint-0.35.0 vs lib/scss_lint/utils.rb in scss-lint-0.36.0

- old
+ new

@@ -80,9 +80,25 @@ node.node_parent .children .select { |child| child.is_a?(Sass::Tree::Node) } end + # Return nth-ancestor of a node, where 1 is the parent, 2 is grandparent, + # etc. + # + # @param node [Sass::Tree::Node, Sass::Script::Tree::Node] + # @param level [Integer] + # @return [Sass::Tree::Node, Sass::Script::Tree::Node, nil] + def node_ancestor(node, levels) + while levels > 0 + node = node.node_parent + return unless node + levels -= 1 + end + + node + end + def pluralize(value, word) value == 1 ? "#{value} #{word}" : "#{value} #{word}s" end # Sass doesn't define an equality operator for Sass::Source::Position