lib/scss_lint/linter/indentation.rb in scss-lint-0.24.1 vs lib/scss_lint/linter/indentation.rb in scss-lint-0.25.0
- old
+ new
@@ -23,11 +23,13 @@
def check_indentation(node)
return unless node.line
# Ignore the case where the node is on the same line as its previous
# sibling or its parent, as indentation isn't possible
- return if (previous = previous_node(node)) && previous.line == node.line
+ return if (previous = previous_node(node)) &&
+ (previous.line == node.line ||
+ previous.source_range.end_pos.line == node.line)
actual_indent = engine.lines[node.line - 1][/^(\s*)/, 1]
return if actual_indent.length == @indent
@@ -41,12 +43,38 @@
def visit_if(node, &block)
check_and_visit_children(node, &block)
visit(node.else) if node.else
end
+ # Need to define this explicitly since @at-root directives can contain
+ # inline selectors which produces the same parse tree as if the selector was
+ # nested within it. For example:
+ #
+ # @at-root {
+ # .something {
+ # ...
+ # }
+ # }
+ #
+ # ...and...
+ #
+ # @at-root .something {
+ # ...
+ # }
+ #
+ # ...produce the same parse tree, but result in different indentation
+ # levels.
+ def visit_atroot(node, &block)
+ if at_root_contains_inline_selector?(node)
+ return if check_indentation(node)
+ yield
+ else
+ check_and_visit_children(node, &block)
+ end
+ end
+
# Define node types that increase indentation level
- alias_method :visit_atroot, :check_and_visit_children
alias_method :visit_directive, :check_and_visit_children
alias_method :visit_each, :check_and_visit_children
alias_method :visit_for, :check_and_visit_children
alias_method :visit_function, :check_and_visit_children
alias_method :visit_media, :check_and_visit_children
@@ -64,7 +92,15 @@
alias_method :visit_extend, :check_indentation
alias_method :visit_import, :check_indentation
alias_method :visit_return, :check_indentation
alias_method :visit_variable, :check_indentation
alias_method :visit_warn, :check_indentation
+
+ private
+
+ def at_root_contains_inline_selector?(node)
+ return unless node.children.any?
+
+ same_position?(node.source_range.end_pos, node.children.first.source_range.start_pos)
+ end
end
end