Skip to content

Commit 04dda9f

Browse files
committed
Fix inconsistent sorting for the same name properties
1 parent fce6b85 commit 04dda9f

8 files changed

+136
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
div {
2+
position: fixed;
3+
top: 0;
4+
top: $header-height;
5+
a: 0;
6+
b: 1;
7+
c: 2;
8+
d: 3;
9+
e: 4;
10+
f: 5;
11+
g: 6;
12+
h: 7;
13+
}
14+
15+
div {
16+
position: fixed;
17+
top: $header-height;
18+
top: 0;
19+
a: 0;
20+
b: 1;
21+
c: 2;
22+
d: 3;
23+
e: 4;
24+
f: 5;
25+
g: 6;
26+
h: 7;
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
div {
2+
position: fixed;
3+
top: 0;
4+
top: $header-height;
5+
a: 0;
6+
b: 1;
7+
c: 2;
8+
d: 3;
9+
e: 4;
10+
f: 5;
11+
g: 6;
12+
h: 7;
13+
}
14+
15+
div {
16+
position: fixed;
17+
top: $header-height;
18+
top: 0;
19+
a: 0;
20+
b: 1;
21+
c: 2;
22+
d: 3;
23+
e: 4;
24+
f: 5;
25+
g: 6;
26+
h: 7;
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.header {
2+
padding-bottom: 20px;
3+
-webkit-box-pack: justify;
4+
-ms-flex-pack: justify;
5+
justify-content: space-between;
6+
display: -webkit-box;
7+
display: -ms-flexbox;
8+
display: flex;
9+
-webkit-box-align: center;
10+
-ms-flex-align: center;
11+
align-items: center;
12+
-ms-flex-wrap: wrap;
13+
flex-wrap: wrap;
14+
}
15+
16+
.header {
17+
-webkit-box-pack: justify;
18+
-ms-flex-pack: justify;
19+
justify-content: space-between;
20+
display: -webkit-box;
21+
display: -ms-flexbox;
22+
display: flex;
23+
-webkit-box-align: center;
24+
-ms-flex-align: center;
25+
align-items: center;
26+
-ms-flex-wrap: wrap;
27+
flex-wrap: wrap;
28+
padding-bottom: 20px;
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.header {
2+
align-items: center;
3+
-webkit-box-align: center;
4+
-webkit-box-pack: justify;
5+
display: -webkit-box;
6+
display: -ms-flexbox;
7+
display: flex;
8+
-ms-flex-align: center;
9+
-ms-flex-pack: justify;
10+
-ms-flex-wrap: wrap;
11+
flex-wrap: wrap;
12+
justify-content: space-between;
13+
padding-bottom: 20px;
14+
}
15+
16+
.header {
17+
align-items: center;
18+
-webkit-box-align: center;
19+
-webkit-box-pack: justify;
20+
display: -webkit-box;
21+
display: -ms-flexbox;
22+
display: flex;
23+
-ms-flex-align: center;
24+
-ms-flex-pack: justify;
25+
-ms-flex-wrap: wrap;
26+
flex-wrap: wrap;
27+
justify-content: space-between;
28+
padding-bottom: 20px;
29+
}

lib/properties-order/__tests__/properties-order.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test(
100100

101101
test(
102102
'Should preserve order if properties have same name',
103-
() => runTest('properties-have-same-name',
103+
() => runTest('properties-have-same-name-1',
104104
{
105105
'properties-order': [
106106
'position',
@@ -111,6 +111,29 @@ test(
111111
)
112112
);
113113

114+
test(
115+
'Should preserve order if properties have same name',
116+
() => runTest('properties-have-same-name-2',
117+
{
118+
'properties-order': [
119+
'position',
120+
'z-index',
121+
],
122+
},
123+
__dirname
124+
)
125+
);
126+
127+
test(
128+
'Should preserve order if properties have same name',
129+
() => runTest('properties-have-same-name-3',
130+
{
131+
'properties-order': 'alphabetical',
132+
},
133+
__dirname
134+
)
135+
);
136+
114137
test(
115138
`Should not remove first comment in the rule if it's not on separate line (properties-order)`,
116139
() => runTest('first-comment-in-the-rule',

lib/sorting.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ function sortDeclarations(a, b) {
2020
if (!postcss.vendor.prefix(a.name).length && postcss.vendor.prefix(b.name).length) {
2121
return 1;
2222
}
23-
24-
// Otherwise keep original order
25-
return 0;
2623
}
2724

2825
if (!_.isUndefined(a.orderData) && !_.isUndefined(b.orderData)) {
@@ -77,9 +74,6 @@ function sortDeclarationsAlphabetically(a, b) {
7774
if (!postcss.vendor.prefix(a.name).length && postcss.vendor.prefix(b.name).length) {
7875
return 1;
7976
}
80-
81-
// Otherwise keep original order
82-
return 0;
8377
}
8478

8579
return a.initialIndex - b.initialIndex;

0 commit comments

Comments
 (0)