Skip to content

Commit

Permalink
Add support for "declaration-block-properties-order" rule
Browse files Browse the repository at this point in the history
Related to #3
  • Loading branch information
nkt committed Jul 1, 2016
1 parent a035a64 commit d9c2100
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var scss = require('postcss-scss')

var params = require('./lib/params')
var formatAtRules = require('./lib/formatAtRules')
var formatOrder = require('./lib/formatOrder')
var formatRules = require('./lib/formatRules')
var formatComments = require('./lib/formatComments')
var formatSassVariables = require('./lib/formatSassVariables')
Expand All @@ -15,6 +16,7 @@ var stylefmt = postcss.plugin('stylefmt', function (options) {
return params(options).then(function (params) {
formatComments(root, params)
formatAtRules(root, params)
formatOrder(root, params)
formatRules(root, params)
formatSassVariables(root, params)
return root
Expand Down
16 changes: 16 additions & 0 deletions lib/formatOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var sorting = require('postcss-sorting');

function formatOrder(root, params) {
var sortOrder = params.stylelint['declaration-block-properties-order'];
if (!Array.isArray(sortOrder)) {
return;
}

var sort = sorting({
'sort-order': sortOrder
});

sort(root);
}

module.exports = formatOrder;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"object-assign": "^4.1.0",
"postcss": "^5.0.21",
"postcss-scss": "^0.1.8",
"postcss-sorting": "^1.6.1",
"recursive-readdir": "^2.0.0",
"repeat-string": "^1.5.4",
"resolve-from": "^2.0.0",
Expand Down
12 changes: 12 additions & 0 deletions test/stylelint/declaration-block-properties-order/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rules": {
"declaration-block-properties-order": [
"@atrule",
"display",
"width",
"height",
"color",
"background"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a {
height: 20px;
color: #000;
@include "foo";
width: 10px;
display: block;
background: #fff;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a {
@include "foo";
display: block;
width: 10px;
height: 20px;
color: #000;
background: #fff;
}

0 comments on commit d9c2100

Please sign in to comment.