From 4edd792521198b288723abbffac3289e1c6d767c Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Thu, 14 Jul 2016 16:29:57 +0300 Subject: [PATCH] Add support for groups in `declaration-block-properties-order` --- lib/formatOrder.js | 15 ++++++++++- .../.stylelintrc | 25 +++++++++++++++++++ ...laration-block-properties-order-groups.css | 10 ++++++++ ...tion-block-properties-order-groups.out.css | 10 ++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/stylelint/declaration-block-properties-order-groups/.stylelintrc create mode 100644 test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.css create mode 100644 test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.out.css diff --git a/lib/formatOrder.js b/lib/formatOrder.js index 683c4fc..ba96689 100644 --- a/lib/formatOrder.js +++ b/lib/formatOrder.js @@ -6,8 +6,21 @@ function formatOrder(root, params) { return; } + // sort order can contain groups, so it needs to be flat for postcss-sorting + var flattenedSortOrder = []; + + sortOrder.forEach(function(item) { + if (typeof item === 'string') { + flattenedSortOrder.push(item); + } else if (typeof item === 'object' && Array.isArray(item.properties)) { + item.properties.forEach(function(prop) { + flattenedSortOrder.push(prop); + }); + } + }); + var sort = sorting({ - 'sort-order': sortOrder + 'sort-order': flattenedSortOrder }); sort(root); diff --git a/test/stylelint/declaration-block-properties-order-groups/.stylelintrc b/test/stylelint/declaration-block-properties-order-groups/.stylelintrc new file mode 100644 index 0000000..a0e0ae6 --- /dev/null +++ b/test/stylelint/declaration-block-properties-order-groups/.stylelintrc @@ -0,0 +1,25 @@ +{ + "rules": { + "declaration-block-properties-order": [ + { + "properties": [ + "font-size", + "font-weight" + ] + }, + "display", + { + "properties": [ + ] + }, + "width", + { + "object-without-properties-property": true + }, + "height", + "color", + "background", + "opacity" + ] + } +} diff --git a/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.css b/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.css new file mode 100644 index 0000000..d510565 --- /dev/null +++ b/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.css @@ -0,0 +1,10 @@ +a { + height: 20px; + font-size: 18px; + color: #000; + opacity: .8; + width: 10px; + display: block; + font-weight: normal; + background: #fff; +} diff --git a/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.out.css b/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.out.css new file mode 100644 index 0000000..b05599c --- /dev/null +++ b/test/stylelint/declaration-block-properties-order-groups/declaration-block-properties-order-groups.out.css @@ -0,0 +1,10 @@ +a { + font-size: 18px; + font-weight: normal; + display: block; + width: 10px; + height: 20px; + color: #000; + background: #fff; + opacity: .8; +}