Skip to content

Commit

Permalink
Fix error when sorting leftover variable definitions. [closes csscomb…
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed May 17, 2019
1 parent cbd6815 commit 1f27f9e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/options/sort-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ module.exports = {
a = a.node.first().first().content;
b = b.node.first().first().content;

if (Array.isArray(a)) {
a = a[0].content;
}

if (Array.isArray(b)) {
b = b[0].content;
}

// Get prefix and unprefixed part. For example:
// ['-o-animation', '-o-', 'animation']
// ['color', '', 'color']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div {$blue: steelblue; $red: tomato; }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div {$red: tomato; $blue: steelblue; }
11 changes: 11 additions & 0 deletions test/options/sort-order-fallback/process/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,15 @@ describe('Option `sort-order-fallback`, process', function() {
return test.shouldBeEqual('test.css', 'test-3.expected.css');
});
});

describe('scss', function() {
it('Should sort leftover variables alphabetically', function() {
let config = {
'sort-order': [],
'sort-order-fallback': 'abc'
};
let test = new Test(this, config);
return test.shouldBeEqual('leftovers-variable.scss', 'leftovers-variable.expected.scss');
});
});
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
div {$red: tomato; color: $tomato; }
div {$red: tomato; color: $red; }
2 changes: 1 addition & 1 deletion test/options/sort-order/process/scss/variable.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
div { color: $tomato; $red: tomato; }
div { color: $red; $red: tomato; }

0 comments on commit 1f27f9e

Please sign in to comment.