Skip to content

Commit 91486e0

Browse files
committed
Block indent: Change acceptable values
`block-indent` option now accepts only these kind 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 e792f82 commit 91486e0

4 files changed

Lines changed: 42 additions & 23 deletions

File tree

.csscomb.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"node_modules/**"
55
],
66
"always-semicolon": true,
7-
"block-indent": true,
7+
"block-indent": " ",
88
"colon-space": true,
99
"color-case": "lower",
1010
"color-shorthand": true,

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Example configuration:
149149
"verbose": true,
150150

151151
"always-semicolon": true,
152-
"block-indent": true,
152+
"block-indent": " ",
153153
"colon-space": true,
154154
"color-case": "lower",
155155
"color-shorthand": true,
@@ -330,10 +330,10 @@ div {
330330
331331
**Note**: better to use with [rule-indent](#rule-indent)
332332
333-
Available values:
334-
* `{Boolean}` `true` (means 4 spaces)
335-
* `{Number}` of spaces
336-
* `{String}` of whitespace characters (`/[ \t]+/`)
333+
Acceptable values:
334+
* `{Number}` of spaces;
335+
* `{String}` of whitespaces or tabs. If there is any other character in the
336+
string, the value will not be set.
337337
338338
Example: `{ "block-indent": 2 }`
339339
@@ -351,6 +351,23 @@ a { color: red
351351
}
352352
```
353353
354+
Example: `{ "block-indent": " " }`
355+
356+
```css
357+
/* before */
358+
a { color: red }
359+
@media all { a { color: green } }
360+
361+
/* after */
362+
a { color: red
363+
}
364+
@media all {
365+
a { color: green
366+
}
367+
}
368+
```
369+
370+
354371
### colon-space
355372
356373
Available values:

lib/options/block-indent.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]+$/)) this._value = value;
14+
} else if (typeof value === 'string' && value.match(/^[ \t]+$/)) {
15+
this._value = value;
16+
}
17+
1518
if (typeof this._value === 'string') return this;
1619
},
1720

test/block-indent.js

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

44
describe('options/block-indent', function() {
55
var comb;
6+
67
beforeEach(function() {
78
comb = new Comb();
89
});
10+
911
it('Invalid Number value should not change space after brace', function() {
12+
var input = 'a { color: red }';
1013
comb.configure({ 'block-indent': 3.5 });
11-
assert.equal(
12-
comb.processString('a { color: red }'),
13-
'a { color: red }'
14-
);
14+
assert.equal(comb.processString(input), input);
1515
});
16+
1617
it('Invalid String value should not change space after brace', function() {
18+
var input = 'a { color: red }';
1719
comb.configure({ 'block-indent': 'foobar' });
18-
assert.equal(
19-
comb.processString('a { color: red }'),
20-
'a { color: red }'
21-
);
20+
assert.equal(comb.processString(input), input);
2221
});
23-
it('True Boolean value should set 4 spaces indent', function() {
22+
23+
it('Boolean value should not change space after brace', function() {
24+
var input = ' \n a { color: red } @media all {.input__control { color: #000;\n}\n}';
2425
comb.configure({ 'block-indent': true });
25-
assert.equal(
26-
comb.processString(' \n a { color: red } @media all {.input__control { color: #000;\n}\n}'),
27-
' \na { color: red \n}\n@media all {\n .input__control { color: #000;\n }\n}'
28-
);
26+
assert.equal(comb.processString(input), input);
2927
});
28+
3029
it('Valid Number value should set equal space after brace', function() {
3130
comb.configure({ 'block-indent': 3 });
3231
assert.equal(

0 commit comments

Comments
 (0)