lib/scss_lint/linter.rb in scss-lint-0.21.0 vs lib/scss_lint/linter.rb in scss-lint-0.22.0

- old
+ new

@@ -35,13 +35,10 @@ # @return [String] the character at the given [Sass::Source::Position] def character_at(source_position, offset = 0) actual_line = source_position.line - 1 actual_offset = source_position.offset + offset - 1 - # Return a newline if offset points at the very end of the line - 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. # @@ -58,21 +55,36 @@ source = engine.lines[current_line][start_pos..-1] end current_line += 1 while current_line < last_line - source += "#{engine.lines[current_line]}\n" + source += "#{engine.lines[current_line]}" 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" + if source_range.start_pos.line != source_range.end_pos.line + source += "#{(engine.lines[current_line] || '')[0...source_range.end_pos.offset]}" end source + end + + # Returns whether a given node spans only a single line. + # + # @param node [Sass::Tree::Node] + # @return [true,false] whether the node spans a single line + def node_on_single_line(node) + return if node.source_range.start_pos.line != node.source_range.end_pos.line + + # The Sass parser reports an incorrect source range if the trailing curly + # brace is on the next line, e.g. + # + # p { + # } + # + # Since we don't want to count this as a single line node, check if the + # last character on the first line is an opening curly brace. + engine.lines[node.line - 1].strip[-1] != '{' end # Modified so we can also visit selectors in linters # # @param node [Sass::Tree::Node, Sass::Script::Tree::Node,