From 1e4de016c240523374f01a9a82a3339b02329fba Mon Sep 17 00:00:00 2001 From: Kyle Peatt Date: Fri, 1 Aug 2014 14:56:34 -0700 Subject: [PATCH 1/2] Add rules delimiter --- .csscomb.json | 221 +++++++++++++++++++++++++++++++++ doc/options.md | 5 + lib/options/rules-delimiter.js | 35 ++++++ test.scss | 12 ++ 4 files changed, 273 insertions(+) create mode 100644 .csscomb.json create mode 100644 lib/options/rules-delimiter.js create mode 100644 test.scss diff --git a/.csscomb.json b/.csscomb.json new file mode 100644 index 00000000..beff714d --- /dev/null +++ b/.csscomb.json @@ -0,0 +1,221 @@ +{ + "exclude": [ + ".git/**", + "node_modules/**", + "bower_components/**" + ], + "verbose": true, + "always-semicolon": true, + "block-indent": 4, + "colon-space": ["", " "], + "color-case": "lower", + "color-shorthand": true, + "combinator-space": [" ", " "], + "element-case": "lower", + "eof-newline": true, + "leading-zero": true, + "quotes": "single", + "rule-indent": " ", + "stick-brace": " ", + "unitless-zero": true, + "space-before-closing-brace": "\n", + "space-before-colon": "", + "space-after-colon": " ", + "space-before-combinator": " ", + "space-after-combinator": " ", + "space-before-opening-brace": " ", + "space-after-opening-brace": "\n", + "space-after-selector-delimiter": "\n", + "space-before-selector-delimiter": "", + "rules-delimiter": 1, + "sort-order": [ + [ + "$variable" + ], + [ + "$include" + ], + [ + "content", + "quotes", + "counter-reset", + "counter-increment" + ], + [ + "position", + "top", + "right", + "bottom", + "left", + "z-index" + ], + [ + "display", + "overflow", + "overflow-x", + "overflow-y", + "clip", + "float", + "clear", + "table-layout", + "empty-cells", + "caption-side", + "border-spacing", + "border-collapse", + "flex-flow", + "flex-direction", + "flex-wrap", + "justify-content", + "align-items", + "align-content", + "flex", + "flex-grow", + "flex-shrink", + "flex-basis", + "align-self", + "order", + "box-sizing", + "width", + "min-width", + "max-width", + "height", + "min-height", + "max-height", + "margin", + "margin-top", + "margin-right", + "margin-bottom", + "margin-left", + "padding", + "padding-top", + "padding-right", + "padding-bottom", + "padding-left", + "border", + "border-width", + "border-style", + "border-color", + "border-top", + "border-top-width", + "border-top-style", + "border-top-color", + "border-right", + "border-right-width", + "border-right-style", + "border-right-color", + "border-bottom", + "border-bottom-width", + "border-bottom-style", + "border-bottom-color", + "border-left", + "border-left-width", + "border-left-style", + "border-left-color" + ], + [ + "visibility", + "opacity", + "border-radius", + "border-top-left-radius", + "border-top-right-radius", + "border-bottom-right-radius", + "border-bottom-left-radius", + "border-image", + "border-image-source", + "border-image-slice", + "border-image-width", + "border-image-outset", + "border-image-repeat", + "background", + "background-color", + "background-image", + "background-repeat", + "background-attachment", + "background-position", + "background-position-x", + "background-position-y", + "background-origin", + "background-size", + "background-clip", + "box-shadow", + "box-decoration-break", + "outline", + "outline-width", + "outline-style", + "outline-color", + "filter" + ], + [ + "color", + "font", + "font-family", + "font-style", + "font-weight", + "font-variant", + "font-size", + "font-size-adjust", + "line-height", + "letter-spacing", + "word-spacing", + "direction", + "word-wrap", + "overflow-wrap", + "word-break", + "hyphens", + "white-space", + "text-align", + "text-align-last", + "text-indent", + "text-overflow", + "text-transform", + "text-decoration", + "text-shadow", + "text-rendering", + "text-size-adjust", + "vertical-align", + "tab-size", + "list-style", + "list-style-position", + "list-style-type", + "list-style-image" + ], + [ + "cursor", + "user-select", + "resize", + "pointer-events" + ], + [ + "transform", + "transform-function", + "transform-origin", + "transform-style", + "perspective", + "perspective-origin", + "backface-visibility" + ], + [ + "transition", + "transition-property", + "transition-duration", + "transition-timing-function", + "transition-delay", + "animation", + "animation-name", + "animation-duration", + "animation-timing-function", + "animation-delay", + "animation-iteration-count", + "animation-direction", + "animation-fill-mode", + "animation-play-state" + ], + [ + "-webkit-appearance", + "-moz-appearance", + "-webkit-overflow-scrolling", + "-webkit-tap-highlight-color", + "-webkit-text-stroke" + ] + ] +} diff --git a/doc/options.md b/doc/options.md index dea8a478..2ffd5da1 100644 --- a/doc/options.md +++ b/doc/options.md @@ -11,6 +11,7 @@ Here is a full list in the same order they are applied while processing css: - [element-case](#element-case) - [leading-zero](#leading-zero) - [quotes](#quotes) +- [rules-delimiter](#rules-delimiter) - [strip-spaces](#strip-spaces) - [eof-newline](#eof-newline) - [space-after-combinator](#space-after-combinator) @@ -802,6 +803,10 @@ a } ``` +## rules-delimiter + +Adds a number of blank lines or string before new rules + ## strip-spaces Whether to trim trailing spaces. diff --git a/lib/options/rules-delimiter.js b/lib/options/rules-delimiter.js new file mode 100644 index 00000000..c38183d6 --- /dev/null +++ b/lib/options/rules-delimiter.js @@ -0,0 +1,35 @@ +module.exports = { + name: 'rules-delimiter', + + syntax: ['scss'], + + runBefore: "strip-spaces", + + setValue: function(value) { + if (typeof value === 'number') { + value = Array(value + 1).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' || + (node[i-2] && node[i-2][0] !== 'commentML' && node[i-2][0] !== 'commentSL')) { + console.log('Changing ', currentNode[0], ' because of ', previousNode); + + node.splice(i - 1, 0, ['s', value]); + } + } + } + } +}; \ No newline at end of file diff --git a/test.scss b/test.scss new file mode 100644 index 00000000..0d055b03 --- /dev/null +++ b/test.scss @@ -0,0 +1,12 @@ +body { + color: red; + + &::after { + content: ''; + } +} + + +a { + background: blue; +} From b6ecea3f33af5bb46c586f049d141e12fc2e0160 Mon Sep 17 00:00:00 2001 From: Kyle Peatt Date: Wed, 20 Aug 2014 10:21:55 -0700 Subject: [PATCH 2/2] Update rules delimiter to fix issue https://gist.github.com/thebugs/977813e0040a4145cf9d --- lib/options/rules-delimiter.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/options/rules-delimiter.js b/lib/options/rules-delimiter.js index c38183d6..cd669134 100644 --- a/lib/options/rules-delimiter.js +++ b/lib/options/rules-delimiter.js @@ -1,35 +1,34 @@ module.exports = { name: 'rules-delimiter', - + syntax: ['scss'], - + runBefore: "strip-spaces", - + setValue: function(value) { if (typeof value === 'number') { - value = Array(value + 1).join('\n'); + 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] + previousNode = node[i - 1]; if(currentNode[0] === 'ruleset' && previousNode) { - if(previousNode[0] !== 's' || - (node[i-2] && node[i-2][0] !== 'commentML' && node[i-2][0] !== 'commentSL')) { - console.log('Changing ', currentNode[0], ' because of ', previousNode); + if(previousNode[0] === 's') { + if (node[i - 2] && (node[i - 2][0] === 'commentSL' || node[i - 2][0] === 'commentML')) continue; - node.splice(i - 1, 0, ['s', value]); + node[i - 1][1] = previousNode[1].replace(/\n*/, value); } } } } -}; \ No newline at end of file +};