Skip to content

Commit 2d39924

Browse files
committed
Fix removing comments in rule if they are only children
1 parent a4f030d commit 2d39924

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
222222
return a.initialIndex - b.initialIndex;
223223
});
224224

225-
rule.removeAll();
226-
rule.append(processed);
225+
if (processed.length) {
226+
rule.removeAll();
227+
rule.append(processed);
228+
}
227229

228230
// Remove all empty lines and add empty lines between groups
229231
rule.each(function (node) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
div {
2+
/* comment 1*/
3+
}
4+
5+
section {
6+
/* comment 2 */
7+
a {
8+
/* comment 3 */
9+
}
10+
}
11+
12+
article {
13+
@media (min-width: 300px) {
14+
/* comment 4 */
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
div {
2+
/* comment 1*/
3+
}
4+
5+
section {
6+
/* comment 2 */
7+
a {
8+
/* comment 3 */
9+
}
10+
}
11+
12+
article {
13+
@media (min-width: 300px) {
14+
/* comment 4 */
15+
}
16+
}

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ test('Should work correctly with comments in case of 1 group', t => {
6262
] });
6363
});
6464

65+
test('Should not remove comments in rules if they are only children', t => {
66+
return run(t, 'rules-with-comments-only');
67+
});
68+
6569
test('Should work correctly with one comment in case of 1 group. SCSS syntax', t => {
6670
return run(t, 'single-group-comment-scss.scss', { 'sort-order': [
6771
['border-bottom', 'font-style']

0 commit comments

Comments
 (0)