Skip to content

Commit aa0f8d0

Browse files
committed
Fix DeclarationOrder false positives
As of Ruby 2.2.0 the sorting algorithm appears to have changed, which results in an unstable sort of elements. These causes a false positive since two nodes of the same type could have their order shuffled. Fix this by including the index of the node in the sort so we preserve order explicitly.
1 parent eb78c56 commit aa0f8d0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master (unreleased)
44

55
* Fix `PropertyUnits` to not error on properties with function call values
6+
* Fix `DeclarationOrder` false positives on lines of the same type of node
67

78
## 0.36.0
89

lib/scss_lint/linter/declaration_order.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ def important_node?(node)
3434
end
3535

3636
def check_node(node)
37-
children = node.children.select { |n| important_node?(n) }
38-
.map { |n| [n, node_declaration_type(n)] }
37+
children = node.children.each_with_index
38+
.select { |n, _| important_node?(n) }
39+
.map { |n, i| [n, node_declaration_type(n), i] }
3940

40-
sorted_children = children.sort do |(_, a_type), (_, b_type)|
41-
DECLARATION_ORDER.index(a_type) <=> DECLARATION_ORDER.index(b_type)
41+
sorted_children = children.sort do |(_, a_type, i), (_, b_type, j)|
42+
[DECLARATION_ORDER.index(a_type), i] <=> [DECLARATION_ORDER.index(b_type), j]
4243
end
4344

4445
check_children_order(sorted_children, children)

0 commit comments

Comments
 (0)