lib/scss_lint/linter.rb in scss-lint-0.23.1 vs lib/scss_lint/linter.rb in scss-lint-0.24.0

- old
+ new

@@ -16,25 +16,20 @@ @config = config @engine = engine visit(engine.tree) end + protected + # Helper for creating lint from a parse tree node # - # @param node_or_line [Sass::Script::Tree::Node, Sass::Engine::Line] + # @param node_or_line_or_location [Sass::Script::Tree::Node, Fixnum, SCSSLint::Location] # @param message [String] - def add_lint(node_or_line, message) - location = if node_or_line.respond_to?(:source_range) && node_or_line.source_range - location_from_range(node_or_line.source_range) - elsif node_or_line.respond_to?(:line) - Location.new(node_or_line.line) - else - Location.new(node_or_line) - end - - @lints << Lint.new(engine.filename, - location, + def add_lint(node_or_line_or_location, message) + @lints << Lint.new(self, + engine.filename, + extract_location(node_or_line_or_location), message) end # Extract {SCSSLint::Location} from a {Sass::Source::Range}. # @@ -126,9 +121,24 @@ # Sass::Script::Value::Base] def visit_children(parent) parent.children.each do |child| child.node_parent = parent visit(child) + end + end + + private + + def extract_location(node_or_line_or_location) + if node_or_line_or_location.is_a?(Location) + node_or_line_or_location + elsif node_or_line_or_location.respond_to?(:source_range) && + node_or_line_or_location.source_range + location_from_range(node_or_line_or_location.source_range) + elsif node_or_line_or_location.respond_to?(:line) + Location.new(node_or_line_or_location.line) + else + Location.new(node_or_line_or_location) end end end end