Skip to content

Commit

Permalink
Added "selectorSeparator" formatting option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Jan 20, 2018
1 parent 4972389 commit 7f806fe
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 10 deletions.
7 changes: 6 additions & 1 deletion edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) }))
Expand Down
25 changes: 16 additions & 9 deletions edge/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="#option-selector-separator">selectorSeparator</a> 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.',
Expand Down Expand Up @@ -168,6 +163,18 @@ module.exports = {
`
}
},
selectorSeparator: {
description: 'Represent a separator between selectors.\nIf the option <a href="#option-insert-new-line-between-selectors">insertNewLineBetweenSelectors</a> is set to <code>true</code>, then <code>,\\n</code> or <code>\\n</code> will be used. Also <code>\\r\\n</code> may be used in place of <code>\\n</code> according to <a href="#option-new-line-char">newLineChar</a> 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',
Expand Down Expand Up @@ -200,7 +207,7 @@ module.exports = {
},
sortProperties: {
description: 'Can be either <code>false</code> for not sorting, <code>"alphabetical"</code> for sorting CSS properties from A to Z, <code>"grouped"</code> for sorting CSS properties according to <a href="https://github.com/SimenB/stylint/blob/master/src/data/ordering.json" target="_blank">Stylint</a> and <a href="https://github.com/tj/nib/blob/master/docs/README.md" target="_blank">nib</a><span class="no-vsce"> -- <a href="#option-sort-properties-grouped" onclick="$(\'#option-sort-properties-grouped\').toggle()">click here to show the full list of sorted properties</a></span>, or an array of property names that defines the property order, for example <code>["color", "background", "display"]</code>.\n' +
'<table id="option-sort-properties-grouped" class="no-vsce" style="display: none;"><tr><th>Sorted properties for "grouped"</th></tr>' + sortedProperties.map(prop => `<tr><td>${prop}</td></tr>`).join('') + '</table>',
'<table id="option-sort-properties-grouped" class="no-vsce" style="display: none;"><tr><th>Sorted properties for "grouped"</th></tr>' + sortedProperties.map(prop => `<tr><td>${prop}</td></tr>`).join('') + '</table>',
oneOf: [
{
enum: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"selectorSeparator": ",\n",
"newLineChar": "\r\n"
}
4 changes: 4 additions & 0 deletions spec/option-selector-separator-comma-new-line/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body,.class1,.class2:hover
display none
.class3,input[type=text]
display block
10 changes: 10 additions & 0 deletions spec/option-selector-separator-comma-new-line/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body,
.class1,
.class2:hover {
display: none;

.class3,
input[type=text] {
display: block;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"selectorSeparator": ", ",
"newLineChar": "\r\n"
}
4 changes: 4 additions & 0 deletions spec/option-selector-separator-comma-space/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body,.class1,.class2:hover
display none
.class3,input[type=text]
display block
7 changes: 7 additions & 0 deletions spec/option-selector-separator-comma-space/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body, .class1, .class2:hover {
display: none;

.class3, input[type=text] {
display: block;
}
}
4 changes: 4 additions & 0 deletions spec/option-selector-separator-comma/formattingOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"selectorSeparator": ",",
"newLineChar": "\r\n"
}
4 changes: 4 additions & 0 deletions spec/option-selector-separator-comma/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body,.class1,.class2:hover
display none
.class3,input[type=text]
display block
7 changes: 7 additions & 0 deletions spec/option-selector-separator-comma/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body,.class1,.class2:hover {
display: none;

.class3,input[type=text] {
display: block;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"selectorSeparator": "\n",
"newLineChar": "\r\n"
}
4 changes: 4 additions & 0 deletions spec/option-selector-separator-new-line/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body,.class1,.class2:hover
display none
.class3,input[type=text]
display block
10 changes: 10 additions & 0 deletions spec/option-selector-separator-new-line/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body
.class1
.class2:hover {
display: none;

.class3
input[type=text] {
display: block;
}
}

0 comments on commit 7f806fe

Please sign in to comment.