Skip to content

Commit f6dc6fd

Browse files
committed
Fix #317: sort-order should not remove empty lines
1 parent 813ffbc commit f6dc6fd

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

lib/options/sort-order.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ module.exports = {
6868
var j;
6969
var nl;
7070

71+
/**
72+
* Remove empty lines in space node.
73+
* @param {node} node Space node.
74+
*/
75+
var removeEmptyLines = function(node) {
76+
node[1] = node[1].replace(/\n[\s\t\n\r]*\n/, '\n');
77+
};
78+
7179
/**
7280
* Check if there are any comments or spaces before
7381
* the declaration/@-rule.
@@ -87,11 +95,6 @@ module.exports = {
8795
return false;
8896
}
8997

90-
// Remove any empty lines:
91-
if (currentNode[0] === 's') {
92-
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
93-
}
94-
9598
// If the node is declaration or @-rule, stop and return all
9699
// found nodes with spaces and comments (if there are any):
97100
if (SC.indexOf(currentNode[0]) === -1) break;
@@ -125,11 +128,6 @@ module.exports = {
125128
// If there is no node, or it is nor spaces neither comment, stop:
126129
if (!currentNode || SC.indexOf(currentNode[0]) === -1) break;
127130

128-
// Remove any empty lines:
129-
if (currentNode[0] === 's') {
130-
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
131-
}
132-
133131
if (['commentML', 'commentSL'].indexOf(currentNode[0]) > -1) {
134132
sc.push(currentNode);
135133
d.push(i + 1);
@@ -349,9 +347,9 @@ module.exports = {
349347
var sc1 = currentNode.sc1;
350348
var sc2 = currentNode.sc2;
351349

352-
sc0.reverse();
353-
sc1.reverse();
354-
sc2.reverse();
350+
sc0.reverse().map(removeEmptyLines);
351+
sc1.reverse().map(removeEmptyLines);
352+
sc2.reverse().map(removeEmptyLines);
355353

356354
// Divide declarations from different groups with an empty line:
357355
if (prevNode && currentNode.groupIndex > prevNode.groupIndex) {

test/options/sort-order-scss.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ describe('options/sort-order (scss)', function() {
113113
});
114114
this.shouldBeEqual('leftovers.scss', 'leftovers.expected.scss');
115115
});
116+
117+
it('Issue 317', function() {
118+
this.comb.configure({ 'sort-order': ['...'] });
119+
this.shouldBeEqual('issue-317.scss');
120+
});
116121
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.tv-header-reminders {
2+
display: inline-block;
3+
position: relative;
4+
vertical-align: top;
5+
6+
&__spin {
7+
background-color: #fff;
8+
display: none;
9+
height: 100%;
10+
left: 0;
11+
position: absolute;
12+
top: 0;
13+
width: 100%;
14+
15+
.spin {
16+
height: 100%;
17+
text-align: center;
18+
}
19+
20+
.spin__icon {
21+
margin-top: 4px;
22+
}
23+
}
24+
25+
&_loading_yes .tv-header-reminders__spin {
26+
display: block;
27+
28+
29+
}
30+
31+
}

0 commit comments

Comments
 (0)