File tree Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -222,8 +222,10 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
222
222
return a . initialIndex - b . initialIndex ;
223
223
} ) ;
224
224
225
- rule . removeAll ( ) ;
226
- rule . append ( processed ) ;
225
+ if ( processed . length ) {
226
+ rule . removeAll ( ) ;
227
+ rule . append ( processed ) ;
228
+ }
227
229
228
230
// Remove all empty lines and add empty lines between groups
229
231
rule . each ( function ( node ) {
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ test('Should work correctly with comments in case of 1 group', t => {
62
62
] } ) ;
63
63
} ) ;
64
64
65
+ test ( 'Should not remove comments in rules if they are only children' , t => {
66
+ return run ( t , 'rules-with-comments-only' ) ;
67
+ } ) ;
68
+
65
69
test ( 'Should work correctly with one comment in case of 1 group. SCSS syntax' , t => {
66
70
return run ( t , 'single-group-comment-scss.scss' , { 'sort-order' : [
67
71
[ 'border-bottom' , 'font-style' ]
You can’t perform that action at this time.
0 commit comments