Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make plugin ignore case while sorting declarations #120

Merged
merged 7 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/__tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ test(`Should throw an error if config has error`, () => {
order: 'Justice Rains From Above',
};

const pluginRun = postcss([plugin(opts)])
.process('', { from: undefined })
.then(() => {
expect('Plugin should throw an error').toBeFalst();
})
.catch((err) => {
throw err;
});

expect(pluginRun).rejects.toBeTruthy();
return expect(postcss([plugin(opts)]).process('', { from: undefined })).rejects.toThrow(
'postcss-sorting: order: Should be an array'
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a {
Border: red;
align-content: center;
font-family: sans-serif;
Display: block;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a {
align-content: center;
Border: red;
Display: block;
font-family: sans-serif;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
div {
position: fixed;
top: 0;
Top: $header-height;
A: 0;
b: 1;
C: 2;
d: 3;
E: 4;
f: 5;
G: 6;
h: 7;
}

div {
position: fixed;
Top: $header-height;
top: 0;
a: 0;
B: 1;
c: 2;
D: 3;
e: 4;
F: 5;
g: 6;
H: 7;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
div {
position: fixed;
top: 0;
Top: $header-height;
A: 0;
b: 1;
C: 2;
d: 3;
E: 4;
f: 5;
G: 6;
h: 7;
}

div {
position: fixed;
Top: $header-height;
top: 0;
a: 0;
B: 1;
c: 2;
D: 3;
e: 4;
F: 5;
g: 6;
H: 7;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.header {
Padding-bottom: 20px;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
Justify-content: space-between;
display: -webkit-box;
Display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
Align-items: center;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}

.header {
-webkit-box-pack: justify;
-ms-Flex-pack: justify;
justify-content: space-between;
Display: -webkit-box;
display: -ms-flexbox;
Display: flex;
-webkit-box-align: center;
-ms-Flex-align: center;
align-items: center;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
padding-bottom: 20px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.header {
Align-items: center;
-webkit-box-align: center;
-webkit-box-pack: justify;
display: -webkit-box;
Display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
-ms-flex-pack: justify;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
Justify-content: space-between;
Padding-bottom: 20px;
}

.header {
align-items: center;
-webkit-box-align: center;
-webkit-box-pack: justify;
Display: -webkit-box;
display: -ms-flexbox;
Display: flex;
-ms-Flex-align: center;
-ms-Flex-pack: justify;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
justify-content: space-between;
padding-bottom: 20px;
}
28 changes: 28 additions & 0 deletions lib/properties-order/__tests__/properties-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ test('Should preserve order if properties have same name', () =>
__dirname
));

test('Should preserve order if properties have same name (case insensitive)', () =>
runTest(
'properties-have-same-name-4',
{
'properties-order': ['position', 'z-index'],
},
__dirname
));

test('Should preserve order if properties have same name (case insensitive)', () =>
runTest(
'properties-have-same-name-5',
{
'properties-order': 'alphabetical',
},
__dirname
));

test(`Should not remove first comment in the rule if it's not on separate line (properties-order)`, () =>
runTest(
'first-comment-in-the-rule',
Expand Down Expand Up @@ -145,6 +163,16 @@ test('Should sort properties alphabetically', () =>
__dirname
));

test('Should sort properties alphabetically regardless of case', () => {
runTest(
'properties-alphabetical-case-insensitive',
{
'properties-order': 'alphabetical',
},
__dirname
);
});

test('Should sort shorthand properties before their longhand versions', () =>
runTest(
'properties-alphabetical-shorthand',
Expand Down
2 changes: 1 addition & 1 deletion lib/properties-order/sortNodeProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function sortNodeProperties(node, { order, unspecifiedPropertie
isStandardSyntaxProperty(childNode.prop) &&
!isCustomProperty(childNode.prop)
) {
let unprefixedPropName = vendor.unprefixed(childNode.prop);
let unprefixedPropName = vendor.unprefixed(childNode.prop).toLowerCase();

// Hack to allow -moz-osx-font-smoothing to be understood
// just like -webkit-font-smoothing
Expand Down
Loading