lib/scss_lint/linter.rb in scss-lint-0.16.1 vs lib/scss_lint/linter.rb in scss-lint-0.17.0

- old
+ new

@@ -39,9 +39,32 @@ return "\n" if actual_offset == engine.lines[actual_line].length engine.lines[actual_line][actual_offset] end + # Extracts the original source code given a range. + def source_from_range(source_range) + current_line = source_range.start_pos.line - 1 + last_line = source_range.end_pos.line - 1 + + source = engine.lines[current_line][(source_range.start_pos.offset - 1)..-1] + + current_line += 1 + while current_line < last_line + source += "#{engine.lines[current_line]}\n" + current_line += 1 + end + + if source_range.start_pos.line != source_range.end_pos.line && + # Sometimes the parser reports ranges ending on the first column of the + # line after the last line; don't include the last line in this case. + engine.lines.count == current_line - 1 + source += "#{engine.lines[current_line][0...source_range.end_pos.offset]}\n" + end + + source + end + # Monkey-patched implementation that adds support for traversing # Sass::Script::Nodes (original implementation only supports # Sass::Tree::Nodes). def self.node_name(node) case node