@@ -59,7 +59,28 @@ function cleanLineBreaks(node) {
5959 return node ;
6060}
6161
62+ function createLineBreaks ( lineBreaksCount ) {
63+ return new Array ( lineBreaksCount + 1 ) . join ( '\n' ) ;
64+ }
65+
66+ function getLinesBetweenChildrenFromOptions ( opts ) {
67+ var options = opts || { } ;
68+ var lines = options [ 'empty-lines-between-children-rules' ] ;
69+
70+ if ( lines === undefined || lines === null ) {
71+ return 0 ;
72+ }
73+
74+ if ( typeof lines !== 'number' || isNaN ( lines ) || ! isFinite ( lines ) || lines < 0 || Math . floor ( lines ) !== lines ) {
75+ throw new Error ( 'Type of "empty-lines-between-children-rules" option must be integer with positive value.' ) ;
76+ }
77+
78+ return lines ;
79+ }
80+
6281module . exports = postcss . plugin ( 'postcss-sorting' , function ( opts ) {
82+ var linesBetweenChildrenRules = getLinesBetweenChildrenFromOptions ( opts ) ;
83+
6384 return function ( css ) {
6485 var order = getSortOrder ( opts ) ;
6586
@@ -196,9 +217,14 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
196217
197218 var prevNode = node . prev ( ) ;
198219
199- if ( prevNode && node . groupIndex > prevNode . groupIndex ) {
200- if ( node . raws . before ) {
201- node . raws . before = '\n' + node . raws . before ;
220+ if ( prevNode && node . raws . before ) {
221+ if ( node . groupIndex > prevNode . groupIndex ) {
222+ node . raws . before = createLineBreaks ( 1 ) + node . raws . before ;
223+ }
224+
225+ // Insert empty lines between children classes
226+ if ( node . type === 'rule' && prevNode . type === 'rule' && linesBetweenChildrenRules > 0 ) {
227+ node . raws . before = createLineBreaks ( linesBetweenChildrenRules ) + node . raws . before ;
202228 }
203229 }
204230 } ) ;
0 commit comments