Skip to content

Commit 7a778ea

Browse files
committed
Fix removing of the first comment in the rule if it's not on separate line
1 parent 2d39924 commit 7a778ea

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
184184

185185
rule.each(function (node, index) {
186186
if (node.type === 'comment') {
187+
if (index === 0 && node.raws.before.indexOf('\n') === -1) {
188+
processed.push(node);
189+
}
190+
187191
return;
188192
}
189193

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div { /* comment 1*/
2+
display: none;
3+
}
4+
5+
section { /* comment 2 */
6+
/* comment 3 */
7+
display: block;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div { /* comment 1*/
2+
display: none;
3+
}
4+
5+
section { /* comment 2 */
6+
/* comment 3 */
7+
display: block;
8+
}

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ test('Should not remove comments in rules if they are only children', t => {
6666
return run(t, 'rules-with-comments-only');
6767
});
6868

69+
test('Should not remove first comment in the rule if it\'s not on separate line', t => {
70+
return run(t, 'first-comment-in-the-rule');
71+
});
72+
6973
test('Should work correctly with one comment in case of 1 group. SCSS syntax', t => {
7074
return run(t, 'single-group-comment-scss.scss', { 'sort-order': [
7175
['border-bottom', 'font-style']

0 commit comments

Comments
 (0)