Skip to content

Commit 14c178f

Browse files
authored
Ignore properties case when sorting declarations (#120)
1 parent 2f81b02 commit 14c178f

9 files changed

+84
-11
lines changed

lib/__tests__/test.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ test(`Should throw an error if config has error`, () => {
1111
order: 'Justice Rains From Above',
1212
};
1313

14-
const pluginRun = postcss([plugin(opts)])
15-
.process('', { from: undefined })
16-
.then(() => {
17-
expect('Plugin should throw an error').toBeFalst();
18-
})
19-
.catch((err) => {
20-
throw err;
21-
});
22-
23-
expect(pluginRun).rejects.toBeTruthy();
14+
return expect(postcss([plugin(opts)]).process('', { from: undefined })).rejects.toThrow(
15+
'postcss-sorting: order: Should be an array'
16+
);
2417
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a {
2+
Border: red;
3+
align-content: center;
4+
font-family: sans-serif;
5+
Display: block;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a {
2+
align-content: center;
3+
Border: red;
4+
Display: block;
5+
font-family: sans-serif;
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
div {
2+
position: fixed;
3+
top: 0;
4+
Top: 0;
5+
}
6+
7+
div {
8+
position: fixed;
9+
Top: 0;
10+
top: 0;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
div {
2+
position: fixed;
3+
top: 0;
4+
Top: 0;
5+
}
6+
7+
div {
8+
position: fixed;
9+
Top: 0;
10+
top: 0;
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.header {
2+
Padding-bottom: 20px;
3+
Justify-content: space-between;
4+
display: -webkit-box;
5+
Display: -ms-flexbox;
6+
display: flex;
7+
Align-items: center;
8+
flex-wrap: wrap;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.header {
2+
Align-items: center;
3+
display: -webkit-box;
4+
Display: -ms-flexbox;
5+
display: flex;
6+
flex-wrap: wrap;
7+
Justify-content: space-between;
8+
Padding-bottom: 20px;
9+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ test('Should preserve order if properties have same name', () =>
9191
__dirname
9292
));
9393

94+
test('Should preserve order if properties have same name (case insensitive)', () =>
95+
runTest(
96+
'properties-have-same-name-4',
97+
{
98+
'properties-order': ['position', 'z-index'],
99+
},
100+
__dirname
101+
));
102+
103+
test('Should preserve order if properties have same name (case insensitive)', () =>
104+
runTest(
105+
'properties-have-same-name-5',
106+
{
107+
'properties-order': 'alphabetical',
108+
},
109+
__dirname
110+
));
111+
94112
test(`Should not remove first comment in the rule if it's not on separate line (properties-order)`, () =>
95113
runTest(
96114
'first-comment-in-the-rule',
@@ -145,6 +163,16 @@ test('Should sort properties alphabetically', () =>
145163
__dirname
146164
));
147165

166+
test('Should sort properties alphabetically regardless of case', () => {
167+
runTest(
168+
'properties-alphabetical-case-insensitive',
169+
{
170+
'properties-order': 'alphabetical',
171+
},
172+
__dirname
173+
);
174+
});
175+
148176
test('Should sort shorthand properties before their longhand versions', () =>
149177
runTest(
150178
'properties-alphabetical-shorthand',

lib/properties-order/sortNodeProperties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function sortNodeProperties(node, { order, unspecifiedPropertie
2525
isStandardSyntaxProperty(childNode.prop) &&
2626
!isCustomProperty(childNode.prop)
2727
) {
28-
let unprefixedPropName = vendor.unprefixed(childNode.prop);
28+
let unprefixedPropName = vendor.unprefixed(childNode.prop).toLowerCase();
2929

3030
// Hack to allow -moz-osx-font-smoothing to be understood
3131
// just like -webkit-font-smoothing

0 commit comments

Comments
 (0)