lib/scss_lint/linter/declaration_order.rb in scss-lint-0.35.0 vs lib/scss_lint/linter/declaration_order.rb in scss-lint-0.36.0
- old
+ new
@@ -33,17 +33,28 @@
DECLARATION_ORDER.include?(node.class)
end
def check_node(node)
children = node.children.select { |n| important_node?(n) }
- .map { |n| node_declaration_type(n) }
+ .map { |n| [n, node_declaration_type(n)] }
- sorted_children = children.sort do |a, b|
- DECLARATION_ORDER.index(a) <=> DECLARATION_ORDER.index(b)
+ sorted_children = children.sort do |(_, a_type), (_, b_type)|
+ DECLARATION_ORDER.index(a_type) <=> DECLARATION_ORDER.index(b_type)
end
- return unless children != sorted_children
- add_lint(node.children.first, MESSAGE)
+ check_children_order(sorted_children, children)
+ end
+
+ # Find the child that is out of place
+ def check_children_order(sorted_children, children)
+ sorted_children.each_with_index do |sorted_item, index|
+ next if sorted_item == children[index]
+
+ add_lint(sorted_item.first.line,
+ "Expected item on line #{sorted_item.first.line} to appear " \
+ "before line #{children[index].first.line}. #{MESSAGE}")
+ break
+ end
end
def node_declaration_type(node)
# If the node has no children, return the class.
return node.class unless node.has_children