Last active
July 22, 2016 22:42
-
-
Save thebugs/977813e0040a4145cf9d to your computer and use it in GitHub Desktop.
rules-delimiter option for csscomb.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
name: 'rules-delimiter', | |
syntax: ['scss'], | |
runBefore: "strip-spaces", | |
setValue: function(value) { | |
if (typeof value === 'number') { | |
value = Array(value + 2).join('\n'); | |
} | |
return value; | |
}, | |
process: function(nodeType, node) { | |
var value = this.getValue('rules-delimiter'), | |
currentNode, | |
previousNode; | |
for(var i = node.length; i--;) { | |
currentNode = node[i]; | |
previousNode = node[i - 1]; | |
if(currentNode[0] === 'ruleset' && previousNode) { | |
if(previousNode[0] === 's') { | |
if (node[i - 2] && (node[i - 2][0] === 'commentSL' || node[i - 2][0] === 'commentML')) continue; | |
node[i - 1][1] = previousNode[1].replace(/\n*/, value); | |
} | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your awesome workaround.
I'm almost happy with this, except one tiny issue:
BEFORE
AFTER
Any solution for this one?