Skip to content

Commit 1428e13

Browse files
committed
Rule indent: Change acceptable values
`rule-indent` 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 a261945 commit 1428e13

4 files changed

Lines changed: 37 additions & 26 deletions

File tree

.csscomb.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"eof-newline": true,
1414
"leading-zero": false,
1515
"remove-empty-rulesets": true,
16-
"rule-indent": true,
16+
"rule-indent": " ",
1717
"stick-brace": "\n",
1818
"strip-spaces": true,
1919
"unitless-zero": true,

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Example configuration:
157157
"eof-newline": true,
158158
"leading-zero": false,
159159
"remove-empty-rulesets": true,
160-
"rule-indent": true,
160+
"rule-indent": " ",
161161
"stick-brace": true,
162162
"strip-spaces": true,
163163
"unitless-zero": true,
@@ -511,10 +511,10 @@ Example: `{ "remove-empty-rulesets": true }` - remove rulesets that have no decl
511511
512512
**Note**: better to use with [block-indent](#block-indent)
513513
514-
Available values:
515-
* `{Boolean}` `true` (means 4 spaces)
516-
* `{Number}` of spaces
517-
* `{String}` of whitespace characters (`/[ \t]+/`)
514+
Acceptable values:
515+
* `{Number}` of spaces;
516+
* `{String}` of whitespaces or tabs. If there is any other character in the
517+
string, the value will not be set.
518518
519519
Example: `{ "rule-indent": 2 }`
520520
@@ -528,6 +528,19 @@ a {
528528
margin:0 }
529529
```
530530
531+
Example: `{ "rule-indent": " " }`
532+
533+
```css
534+
/* before */
535+
a { color:red; margin:0 }
536+
537+
/* after */
538+
a {
539+
color:red;
540+
margin:0 }
541+
```
542+
543+
531544
### sort-order
532545
533546
**Note**: you can use an example of [.csscomb.json](https://github.com/csscomb/csscomb.js/blob/master/.csscomb.json) to set your own sort order

lib/options/rule-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/rule-indent.js

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

44
describe('options/rule-indent', function() {
55
var comb;
6+
67
beforeEach(function() {
78
comb = new Comb();
89
});
10+
911
it('Invalid Number value should not change rule indent', function() {
12+
var input = 'a {\n color: red }';
1013
comb.configure({ 'rule-indent': 3.5 });
11-
assert.equal(
12-
comb.processString('a {\n color: red }'),
13-
'a {\n color: red }'
14-
);
14+
assert.equal(comb.processString(input), input);
1515
});
16+
1617
it('Invalid String value should not change rule indent', function() {
18+
var input = 'a {\n color: red }';
1719
comb.configure({ 'rule-indent': 'foobar' });
18-
assert.equal(
19-
comb.processString('a {\n color: red }'),
20-
'a {\n color: red }'
21-
);
22-
});
23-
it('True Boolean value should set 4 spaces indent', function() {
24-
comb.configure({ 'rule-indent': true });
25-
assert.equal(
26-
comb.processString('a {\n color: red }'),
27-
'a {\n color: red }'
28-
);
20+
assert.equal(comb.processString(input), input);
2921
});
22+
3023
it('Valid Number value should set equal space indent', function() {
3124
comb.configure({ 'rule-indent': 3 });
3225
assert.equal(
3326
comb.processString('a {\n color: red }'),
3427
'a {\n color: red }'
3528
);
3629
});
30+
3731
it('Valid String value should set equal indent', function() {
3832
comb.configure({ 'rule-indent': '\t' });
3933
assert.equal(
@@ -49,8 +43,9 @@ describe('options/rule-indent', function() {
4943
'a { /* foo */\n\tcolor:red; /* bar */\n\n\tbackground: #fff\n}\n'
5044
);
5145
});
46+
5247
it('Valid value should ignore empty blocks', function() {
53-
comb.configure({ 'rule-indent': true });
48+
comb.configure({ 'rule-indent': ' ' });
5449
assert.equal(
5550
comb.processString('a {}'),
5651
'a {}'

0 commit comments

Comments
 (0)