Skip to content

Commit d9c2100

Browse files
committed
Add support for "declaration-block-properties-order" rule
Related to #3
1 parent a035a64 commit d9c2100

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var scss = require('postcss-scss')
33

44
var params = require('./lib/params')
55
var formatAtRules = require('./lib/formatAtRules')
6+
var formatOrder = require('./lib/formatOrder')
67
var formatRules = require('./lib/formatRules')
78
var formatComments = require('./lib/formatComments')
89
var formatSassVariables = require('./lib/formatSassVariables')
@@ -15,6 +16,7 @@ var stylefmt = postcss.plugin('stylefmt', function (options) {
1516
return params(options).then(function (params) {
1617
formatComments(root, params)
1718
formatAtRules(root, params)
19+
formatOrder(root, params)
1820
formatRules(root, params)
1921
formatSassVariables(root, params)
2022
return root

lib/formatOrder.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var sorting = require('postcss-sorting');
2+
3+
function formatOrder(root, params) {
4+
var sortOrder = params.stylelint['declaration-block-properties-order'];
5+
if (!Array.isArray(sortOrder)) {
6+
return;
7+
}
8+
9+
var sort = sorting({
10+
'sort-order': sortOrder
11+
});
12+
13+
sort(root);
14+
}
15+
16+
module.exports = formatOrder;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"object-assign": "^4.1.0",
3434
"postcss": "^5.0.21",
3535
"postcss-scss": "^0.1.8",
36+
"postcss-sorting": "^1.6.1",
3637
"recursive-readdir": "^2.0.0",
3738
"repeat-string": "^1.5.4",
3839
"resolve-from": "^2.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"rules": {
3+
"declaration-block-properties-order": [
4+
"@atrule",
5+
"display",
6+
"width",
7+
"height",
8+
"color",
9+
"background"
10+
]
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a {
2+
height: 20px;
3+
color: #000;
4+
@include "foo";
5+
width: 10px;
6+
display: block;
7+
background: #fff;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a {
2+
@include "foo";
3+
display: block;
4+
width: 10px;
5+
height: 20px;
6+
color: #000;
7+
background: #fff;
8+
}

0 commit comments

Comments
 (0)