From 7f806fe8a1c31887340aaaaec5637122c27e0a72 Mon Sep 17 00:00:00 2001 From: "Anantachai Saothong (Manta)" Date: Sat, 20 Jan 2018 23:31:32 +0700 Subject: [PATCH] Added "selectorSeparator" formatting option --- edge/format.js | 7 +++++- edge/schema.js | 25 ++++++++++++------- .../formattingOptions.json | 4 +++ .../input.styl | 4 +++ .../output.styl | 10 ++++++++ .../formattingOptions.json | 4 +++ .../input.styl | 4 +++ .../output.styl | 7 ++++++ .../formattingOptions.json | 4 +++ .../input.styl | 4 +++ .../output.styl | 7 ++++++ .../formattingOptions.json | 4 +++ .../input.styl | 4 +++ .../output.styl | 10 ++++++++ 14 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 spec/option-selector-separator-comma-new-line/formattingOptions.json create mode 100644 spec/option-selector-separator-comma-new-line/input.styl create mode 100644 spec/option-selector-separator-comma-new-line/output.styl create mode 100644 spec/option-selector-separator-comma-space/formattingOptions.json create mode 100644 spec/option-selector-separator-comma-space/input.styl create mode 100644 spec/option-selector-separator-comma-space/output.styl create mode 100644 spec/option-selector-separator-comma/formattingOptions.json create mode 100644 spec/option-selector-separator-comma/input.styl create mode 100644 spec/option-selector-separator-comma/output.styl create mode 100644 spec/option-selector-separator-new-line/formattingOptions.json create mode 100644 spec/option-selector-separator-new-line/input.styl create mode 100644 spec/option-selector-separator-new-line/output.styl diff --git a/edge/format.js b/edge/format.js index bea7557..6a82017 100644 --- a/edge/format.js +++ b/edge/format.js @@ -117,7 +117,12 @@ function format(content, options = {}) { } // Insert CSS selector(s) - const separator = ',' + (options.insertNewLineBetweenSelectors ? (options.newLineChar + indent) : ' ') + let separator = options.selectorSeparator + if (options.insertNewLineBetweenSelectors && separator.includes('\n') === false) { + separator = separator.trim() + '\n' + } + separator = separator.replace(/\r?\n/, options.newLineChar + indent) + outputBuffer.append(indent + inputNode.nodes.map(node => travel(inputNode, node, indentLevel, true)).join(separator).trim()) outputBuffer.append(travel(inputNode, inputNode.block, indentLevel, false, { potentialCommentNodeInsideTheBlock: _.last(inputNode.nodes) })) diff --git a/edge/schema.js b/edge/schema.js index b1bca9e..17b046e 100644 --- a/edge/schema.js +++ b/edge/schema.js @@ -58,16 +58,11 @@ module.exports = { default: false, }, insertNewLineBetweenSelectors: { - description: 'Insert or remove a new-line between selectors.', + deprecated: true, + description: 'Insert or remove a new-line between selectors.\nPlease use selectorSeparator option instead.', type: 'boolean', default: false, - example: { - values: [true, false], - code: ` - .class1, .class2 - background red - ` - } + hideInDemo: true }, insertSpaceBeforeComment: { description: 'Insert or remove a white-space before a comment.', @@ -168,6 +163,18 @@ module.exports = { ` } }, + selectorSeparator: { + description: 'Represent a separator between selectors.\nIf the option insertNewLineBetweenSelectors is set to true, then ,\\n or \\n will be used. Also \\r\\n may be used in place of \\n according to newLineChar option.', + enum: [',', ', ', ',\n', '\n'], + default: ', ', + example: { + values: [',', ', ', ',\n', '\n'], + code: ` + .class1, .class2 + background red + ` + } + }, tabStopChar: { description: 'Represent an indentation. You may change this to any sequence of white-spaces.', type: 'string', @@ -200,7 +207,7 @@ module.exports = { }, sortProperties: { description: 'Can be either false for not sorting, "alphabetical" for sorting CSS properties from A to Z, "grouped" for sorting CSS properties according to Stylint and nib -- click here to show the full list of sorted properties, or an array of property names that defines the property order, for example ["color", "background", "display"].\n' + - '' + sortedProperties.map(prop => ``).join('') + '', + '' + sortedProperties.map(prop => ``).join('') + '', oneOf: [ { enum: [ diff --git a/spec/option-selector-separator-comma-new-line/formattingOptions.json b/spec/option-selector-separator-comma-new-line/formattingOptions.json new file mode 100644 index 0000000..f591535 --- /dev/null +++ b/spec/option-selector-separator-comma-new-line/formattingOptions.json @@ -0,0 +1,4 @@ +{ + "selectorSeparator": ",\n", + "newLineChar": "\r\n" +} \ No newline at end of file diff --git a/spec/option-selector-separator-comma-new-line/input.styl b/spec/option-selector-separator-comma-new-line/input.styl new file mode 100644 index 0000000..31a739b --- /dev/null +++ b/spec/option-selector-separator-comma-new-line/input.styl @@ -0,0 +1,4 @@ +body,.class1,.class2:hover + display none + .class3,input[type=text] + display block \ No newline at end of file diff --git a/spec/option-selector-separator-comma-new-line/output.styl b/spec/option-selector-separator-comma-new-line/output.styl new file mode 100644 index 0000000..937131a --- /dev/null +++ b/spec/option-selector-separator-comma-new-line/output.styl @@ -0,0 +1,10 @@ +body, +.class1, +.class2:hover { + display: none; + + .class3, + input[type=text] { + display: block; + } +} \ No newline at end of file diff --git a/spec/option-selector-separator-comma-space/formattingOptions.json b/spec/option-selector-separator-comma-space/formattingOptions.json new file mode 100644 index 0000000..908da1f --- /dev/null +++ b/spec/option-selector-separator-comma-space/formattingOptions.json @@ -0,0 +1,4 @@ +{ + "selectorSeparator": ", ", + "newLineChar": "\r\n" +} \ No newline at end of file diff --git a/spec/option-selector-separator-comma-space/input.styl b/spec/option-selector-separator-comma-space/input.styl new file mode 100644 index 0000000..31a739b --- /dev/null +++ b/spec/option-selector-separator-comma-space/input.styl @@ -0,0 +1,4 @@ +body,.class1,.class2:hover + display none + .class3,input[type=text] + display block \ No newline at end of file diff --git a/spec/option-selector-separator-comma-space/output.styl b/spec/option-selector-separator-comma-space/output.styl new file mode 100644 index 0000000..8d7f8b9 --- /dev/null +++ b/spec/option-selector-separator-comma-space/output.styl @@ -0,0 +1,7 @@ +body, .class1, .class2:hover { + display: none; + + .class3, input[type=text] { + display: block; + } +} \ No newline at end of file diff --git a/spec/option-selector-separator-comma/formattingOptions.json b/spec/option-selector-separator-comma/formattingOptions.json new file mode 100644 index 0000000..0bf10ef --- /dev/null +++ b/spec/option-selector-separator-comma/formattingOptions.json @@ -0,0 +1,4 @@ +{ + "selectorSeparator": ",", + "newLineChar": "\r\n" +} \ No newline at end of file diff --git a/spec/option-selector-separator-comma/input.styl b/spec/option-selector-separator-comma/input.styl new file mode 100644 index 0000000..31a739b --- /dev/null +++ b/spec/option-selector-separator-comma/input.styl @@ -0,0 +1,4 @@ +body,.class1,.class2:hover + display none + .class3,input[type=text] + display block \ No newline at end of file diff --git a/spec/option-selector-separator-comma/output.styl b/spec/option-selector-separator-comma/output.styl new file mode 100644 index 0000000..8e2a39a --- /dev/null +++ b/spec/option-selector-separator-comma/output.styl @@ -0,0 +1,7 @@ +body,.class1,.class2:hover { + display: none; + + .class3,input[type=text] { + display: block; + } +} \ No newline at end of file diff --git a/spec/option-selector-separator-new-line/formattingOptions.json b/spec/option-selector-separator-new-line/formattingOptions.json new file mode 100644 index 0000000..6ebc212 --- /dev/null +++ b/spec/option-selector-separator-new-line/formattingOptions.json @@ -0,0 +1,4 @@ +{ + "selectorSeparator": "\n", + "newLineChar": "\r\n" +} \ No newline at end of file diff --git a/spec/option-selector-separator-new-line/input.styl b/spec/option-selector-separator-new-line/input.styl new file mode 100644 index 0000000..31a739b --- /dev/null +++ b/spec/option-selector-separator-new-line/input.styl @@ -0,0 +1,4 @@ +body,.class1,.class2:hover + display none + .class3,input[type=text] + display block \ No newline at end of file diff --git a/spec/option-selector-separator-new-line/output.styl b/spec/option-selector-separator-new-line/output.styl new file mode 100644 index 0000000..f5f277d --- /dev/null +++ b/spec/option-selector-separator-new-line/output.styl @@ -0,0 +1,10 @@ +body +.class1 +.class2:hover { + display: none; + + .class3 + input[type=text] { + display: block; + } +} \ No newline at end of file