Skip to content

Commit 2b6ea64

Browse files
committed
Stick brace: Change acceptable values
`stick-brace` option now accepts only these kinds of values: - `{Number}` of spaces; - `{String}` of whitespaces and tabs. If there is any other character in the string, the value will not be set.
1 parent 1428e13 commit 2b6ea64

3 files changed

Lines changed: 40 additions & 19 deletions

File tree

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Example configuration:
158158
"leading-zero": false,
159159
"remove-empty-rulesets": true,
160160
"rule-indent": " ",
161-
"stick-brace": true,
161+
"stick-brace": "\n",
162162
"strip-spaces": true,
163163
"unitless-zero": true,
164164
"vendor-prefix-align": true
@@ -617,10 +617,10 @@ p {
617617
618618
### stick-brace
619619
620-
Available values:
621-
* `{Boolean}` `true` (means 1 space)
622-
* `{Number}` of spaces
623-
* `{String}` of whitespace characters (`/[ \t\n]+/`)
620+
Acceptable values:
621+
* `{Number}` of spaces;
622+
* `{String}` of whitespaces, tabs or newlines. If there is any other
623+
character in the string, the value will not be set.
624624
625625
Example: `{ "stick-brace": "\n" }`
626626
@@ -633,6 +633,17 @@ a
633633
{ color:red }
634634
```
635635
636+
Example: `{ "stick-brace": 1 }`
637+
638+
```css
639+
/* before */
640+
a{ color:red }
641+
642+
/* after */
643+
a { color:red }
644+
```
645+
646+
636647
### strip-spaces
637648
638649
Available value: `{Boolean}` `true`

lib/options/stick-brace.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ module.exports = {
33
/**
44
* Sets handler value.
55
*
6-
* @param {String|Number|Boolean} value Option value
6+
* @param {String|Number} value Option value
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
1010
delete this._value;
11-
if (value === true) this._value = ' ';
12-
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
11+
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value))) {
1313
this._value = new Array(value + 1).join(' ');
14-
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) this._value = value;
14+
} else if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) {
15+
this._value = value;
16+
}
17+
1518
if (typeof this._value === 'string') return this;
1619
},
1720

test/stick-brace.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,37 @@ var assert = require('assert');
33

44
describe('options/stick-brace', function() {
55
var comb;
6+
67
beforeEach(function() {
78
comb = new Comb();
89
});
10+
11+
it('Boolean value should not change space before brace', function() {
12+
var input = 'a { color: red }';
13+
comb.configure({ 'stick-brace': 'foobar' });
14+
assert.equal(comb.processString(input), input);
15+
});
16+
917
it('Invalid String should not change space before brace', function() {
18+
var input = 'a { color: red }';
1019
comb.configure({ 'stick-brace': 'foobar' });
11-
assert.equal(
12-
comb.processString('a { color: red }'),
13-
'a { color: red }'
14-
);
20+
assert.equal(comb.processString(input), input);
1521
});
16-
it('True Boolean value should set 1 space before brace', function() {
17-
comb.configure({ 'stick-brace': true });
18-
assert.equal(
19-
comb.processString('a{color:red }'),
20-
'a {color:red }'
21-
);
22+
23+
it('Invalid Number should not change space before brace', function() {
24+
var input = 'a { color: red }';
25+
comb.configure({ 'stick-brace': 3.5 });
26+
assert.equal(comb.processString(input), input);
2227
});
28+
2329
it('Valid Number value should set equal space before brace', function() {
2430
comb.configure({ 'stick-brace': 0 });
2531
assert.equal(
2632
comb.processString('a {color:red }'),
2733
'a{color:red }'
2834
);
2935
});
36+
3037
it('Valid String value should set equal space before brace', function() {
3138
comb.configure({ 'stick-brace': '\n' });
3239
assert.equal(

0 commit comments

Comments
 (0)