Skip to content

Commit a2bb251

Browse files
committed
Added an alternative way of setting the colon-space option
1 parent 632cfe4 commit a2bb251

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/options/colon-space.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
setValue: function(value) {
1010
this._value = false;
1111
if (value === true) this._value = 'after';
12-
if (typeof value === 'string' && value.match(/after|before|both/)) this._value = value;
12+
if (typeof value === 'string' && value.match(/after|before|both|(?=.*(?:\s|:))\s*:?\s*/)) this._value = value;
1313
if (!this._value) return;
1414
return this;
1515
},
@@ -20,15 +20,20 @@ module.exports = {
2020
* @param {node} node
2121
*/
2222
process: function(nodeType, node) {
23+
var detectSpaces = this._value.match(/((\s*):)?(\s*)/);
2324
if (nodeType === 'property') {
2425
if (node[node.length - 1][0] === 's') node.pop();
2526
if (this._value === 'both' || this._value === 'before')
2627
node.push(['s', ' ']);
28+
if (detectSpaces && detectSpaces[1])
29+
node.push(['s', detectSpaces[2]]);
2730
}
2831
if (nodeType === 'value') {
2932
if (node[0][0] === 's') node.shift();
3033
if (this._value === 'both' || this._value === 'after')
3134
node.unshift(['s', ' ']);
35+
if (detectSpaces)
36+
node.unshift(['s', detectSpaces[3]]);
3237
}
3338
}
3439

test/colon-space.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,56 @@ describe('options/colon-space', function() {
7777
'a {color : red}'
7878
);
7979
});
80+
it('` ` value should set two spaces after colon', function() {
81+
comb.configure({ 'colon-space': ' ' });
82+
assert.equal(
83+
comb.processString(
84+
'a { color: red }' +
85+
'a{color:red}' +
86+
'a {color : red}'
87+
),
88+
'a { color: red }' +
89+
'a{color: red}' +
90+
'a {color: red}'
91+
);
92+
});
93+
it('`:` value should set no space around colon', function() {
94+
comb.configure({ 'colon-space': ':' });
95+
assert.equal(
96+
comb.processString(
97+
'a { color: red }' +
98+
'a{color:red}' +
99+
'a {color : red}'
100+
),
101+
'a { color:red }' +
102+
'a{color:red}' +
103+
'a {color:red}'
104+
);
105+
});
106+
it('`\n:` value should set a newline before colon', function() {
107+
comb.configure({ 'colon-space': '\n:' });
108+
assert.equal(
109+
comb.processString(
110+
'a { color: red }' +
111+
'a{color:red}' +
112+
'a {color : red}'
113+
),
114+
'a { color\n:red }' +
115+
'a{color\n:red}' +
116+
'a {color\n:red}'
117+
);
118+
});
119+
it('`\t:\t` value should set tabs around colon', function() {
120+
comb.configure({ 'colon-space': '\t:\t' });
121+
assert.equal(
122+
comb.processString(
123+
'a { color: red }' +
124+
'a{color:red}' +
125+
'a {color : red}'
126+
),
127+
'a { color\t:\tred }' +
128+
'a{color\t:\tred}' +
129+
'a {color\t:\tred}'
130+
);
131+
});
80132
});

0 commit comments

Comments
 (0)