lib/scss_lint/linter.rb in scss-lint-0.9.0 vs lib/scss_lint/linter.rb in scss-lint-0.10.0

- old
+ new

@@ -1,7 +1,8 @@ module SCSSLint class Linter < Sass::Tree::Visitors::Base + include SelectorVisitor include Utils attr_reader :engine, :lints def initialize @@ -11,19 +12,20 @@ def run(engine) @engine = engine visit(engine.tree) end + # Define if you want a default message for your linter def description nil end - protected - # Helper for creating lint from a parse tree node - def add_lint(node) - @lints << Lint.new(engine.filename, node.line, description) + def add_lint(node, message = nil) + @lints << Lint.new(engine.filename, + node.line, + message || description) end # Monkey-patched implementation that adds support for traversing # Sass::Script::Nodes (original implementation only supports # Sass::Tree::Nodes). @@ -31,8 +33,18 @@ if node.is_a?(Sass::Script::Node) "script_#{node.class.name.gsub(/.*::(.*?)$/, '\\1').downcase}" else super end + end + + # Modified so we can also visit selectors in linters + def visit(node) + # Visit the selector of a rule if parsed rules are available + if node.is_a?(Sass::Tree::RuleNode) && node.parsed_rules + visit_selector(node.parsed_rules) + end + + super end end end