Skip to content

Commit 0c749ec

Browse files
committed
Fixes bug where the shorthand messes with minimum trimming
1 parent ae03235 commit 0c749ec

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/csscss/redundancy_analyzer.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ def redundancies(minimum = nil)
5656
end
5757
end
5858

59-
if minimum
60-
inverted_matches.delete_if do |key, declarations|
61-
declarations.size < minimum
62-
end
63-
end
64-
6559
# combines selector keys by common declarations
6660
final_inverted_matches = inverted_matches.dup
6761
inverted_matches.to_a[0..-2].each_with_index do |(selector_group1, declarations1), index|
@@ -97,6 +91,11 @@ def redundancies(minimum = nil)
9791
end
9892
end
9993

94+
if minimum
95+
final_inverted_matches.delete_if do |key, declarations|
96+
declarations.size < minimum
97+
end
98+
end
10099

101100
# sort hash by number of matches
102101
sorted_array = final_inverted_matches.sort {|(_, v1), (_, v2)| v2.size <=> v1.size }

test/csscss/redundancy_analyzer_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ module Csscss
171171
[sel(".bar"), sel(".baz")] => [dec("border", "4px solid #4f4f4f")],
172172
[sel(".bar"), sel(".baz"), sel(".foo")] => [dec("border-style", "solid"), dec("border-width", "4px")]
173173
})
174+
175+
RedundancyAnalyzer.new(css).redundancies(2).must_equal({
176+
[sel(".bar"), sel(".baz"), sel(".foo")] => [dec("border-style", "solid"), dec("border-width", "4px")]
177+
})
174178
end
175179

176180
it "reduces padding and margin" do

0 commit comments

Comments
 (0)