Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 260e03a

Browse files
fix: Sort nested rules
1 parent 15fd639 commit 260e03a

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module.exports = postcss.plugin('postcss-sort-alphabetically', function () {
66

77
root.walkRules(rule => {
88
rule.nodes = rule.nodes.sort(function (a, b) {
9-
if (a < b) return -1;
10-
if (a > b) return 1;
9+
if (a.prop < b.prop) return -1;
10+
if (a.prop > b.prop) return 1;
1111
return 0;
1212
});
1313
});

index.test.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function run(input, output, opts) {
1111
}
1212

1313

14-
it('does something', () => {
14+
it('sorts rules', () => {
1515
return run(`a{
1616
border: 1px solid black;
1717
color: red;
@@ -52,3 +52,28 @@ it('does something', () => {
5252
}`
5353
, { });
5454
});
55+
56+
57+
it('sorts nested rules', () => {
58+
return run( `div{
59+
color: red;
60+
border: 1px solid black;
61+
background-color: red;
62+
63+
.class {
64+
color: red;
65+
border: 1px solid black;
66+
}
67+
}`,
68+
`div{
69+
background-color: red;
70+
border: 1px solid black;
71+
color: red;
72+
73+
.class {
74+
border: 1px solid black;
75+
color: red;
76+
}
77+
}`
78+
, { });
79+
});

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "MIT",
2020
"repository": {
2121
"type": "git",
22-
"url": "git+https://github.com/mycsHQ/postcss-sort-alphabetically.git"
22+
"url": "https://github.com/mycsHQ/postcss-sort-alphabetically.git"
2323
},
2424
"bugs": {
2525
"url": "https://github.com/mycsHQ/postcss-sort-alphabetically/issues"
@@ -31,10 +31,12 @@
3131
"devDependencies": {
3232
"eslint": "^3.12.2",
3333
"eslint-config-postcss": "^2.0.2",
34-
"jest": "^18.0.0"
34+
"jest": "^18.0.0",
35+
"semantic-release": "^6.3.2"
3536
},
3637
"scripts": {
37-
"test": "jest && eslint *.js"
38+
"test": "jest && eslint *.js",
39+
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
3840
},
3941
"eslintConfig": {
4042
"extends": "eslint-config-postcss/es5",

0 commit comments

Comments
 (0)