Skip to content

Commit ace82c4

Browse files
committed
Some refactoring — setters updated
Readme and tests fixed: * block-indent * rule-indent * stick-brace
1 parent 538fefa commit ace82c4

6 files changed

Lines changed: 43 additions & 34 deletions

File tree

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Example configuration:
6161
6262
### verbose
6363
64-
Available value: `{Boolean}` true
64+
Available value: `{Boolean}` `true`
6565
6666
Config mode: `{ "verbose": true }`
6767
```bash
@@ -80,7 +80,7 @@ $ ./bin/csscomb ./test -v
8080
8181
### always-semicolon
8282
83-
Available value: `{Boolean}` true
83+
Available value: `{Boolean}` `true`
8484
8585
Example: `{ "always-semicolon": true }`
8686
@@ -97,9 +97,9 @@ a { color: red; }
9797
**Note**: better to use with [rule-indent](#rule-indent)
9898
9999
Available values:
100-
* `{Boolean}` true (means 4 spaces)
100+
* `{Boolean}` `true` (means 4 spaces)
101101
* `{Number}` of spaces
102-
* `{String}` of whitespace characters (`/[ \t]*/`)
102+
* `{String}` of whitespace characters (`/[ \t]+/`)
103103
104104
Example: `{ "block-indent": 2 }`
105105
@@ -120,7 +120,7 @@ a { color: red
120120
### colon-space
121121
122122
Available values:
123-
* `{Boolean}` true (means `after`)
123+
* `{Boolean}` `true` (means `after`)
124124
* `{String}`: `before`, `after`, `both` or any combination of whitespaces
125125
and/or a colon (` `, `: `, `\t:\n\t` etc.)
126126
@@ -270,9 +270,9 @@ p { padding: .5em }
270270
**Note**: better to use with [block-indent](#block-indent)
271271
272272
Available values:
273-
* `{Boolean}` true (means 4 spaces)
273+
* `{Boolean}` `true` (means 4 spaces)
274274
* `{Number}` of spaces
275-
* `{String}` of whitespace characters (`/[ \t]*/`)
275+
* `{String}` of whitespace characters (`/[ \t]+/`)
276276
277277
Example: `{ "rule-indent": 2 }`
278278
@@ -334,8 +334,9 @@ p {
334334
### stick-brace
335335
336336
Available values:
337-
* `{Boolean}` true (means 1 spaces)
338-
* `{String}` of whitespace characters (`/[ \t\n]*/`)
337+
* `{Boolean}` `true` (means 1 space)
338+
* `{Number}` of spaces
339+
* `{String}` of whitespace characters (`/[ \t\n]+/`)
339340
340341
Example: `{ "stick-brace": "\n" }`
341342
@@ -350,7 +351,7 @@ a
350351
351352
### strip-spaces
352353
353-
Available value: `{Boolean}` true
354+
Available value: `{Boolean}` `true`
354355
355356
Example: `{ "strip-spaces": true }`
356357

lib/options/block-indent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = 4;
12-
if (typeof value === 'number' && value === Math.abs(Math.round(value))) value = new Array(value + 1).join(' ');
13-
if (typeof value === 'string' && value.match(/^[ \t]*$/)) this._value = value;
14-
if (!this._value) return;
15-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1616
},
1717

1818
/**

lib/options/rule-indent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = 4;
12-
if (typeof value === 'number' && value === Math.abs(Math.round(value))) value = new Array(value + 1).join(' ');
13-
if (typeof value === 'string' && value.match(/^[ \t]*$/)) this._value = value;
14-
if (!this._value) return;
15-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1616
},
1717

1818
/**

lib/options/stick-brace.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = ' ';
12-
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) this._value = value;
13-
if (!this._value) return;
14-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t\n]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1516
},
1617

1718
/**

test/rule-indent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ describe('options/rule-indent', function() {
66
beforeEach(function() {
77
comb = new Comb();
88
});
9-
it('Invalid Number value should not change space after brace', function() {
9+
it('Invalid Number value should not change rule indent', function() {
1010
comb.configure({ 'rule-indent': 3.5 });
1111
assert.equal(
1212
comb.processString('a {\n color: red }'),
1313
'a {\n color: red }'
1414
);
1515
});
16-
it('Invalid String value should not change space after brace', function() {
16+
it('Invalid String value should not change rule indent', function() {
1717
comb.configure({ 'rule-indent': 'foobar' });
1818
assert.equal(
1919
comb.processString('a {\n color: red }'),
@@ -27,14 +27,14 @@ describe('options/rule-indent', function() {
2727
'a {\n color: red }'
2828
);
2929
});
30-
it('Valid Number value should set equal space after brace', function() {
30+
it('Valid Number value should set equal space indent', function() {
3131
comb.configure({ 'rule-indent': 3 });
3232
assert.equal(
3333
comb.processString('a {\n color: red }'),
3434
'a {\n color: red }'
3535
);
3636
});
37-
it('Valid String value should set equal space after brace', function() {
37+
it('Valid String value should set equal indent', function() {
3838
comb.configure({ 'rule-indent': '\t' });
3939
assert.equal(
4040
comb.processString(

test/stick-brace.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,28 @@ describe('options/stick-brace', function() {
66
beforeEach(function() {
77
comb = new Comb();
88
});
9-
it('Invalid String should not change space after brace', function() {
9+
it('Invalid String should not change space before brace', function() {
1010
comb.configure({ 'stick-brace': 'foobar' });
1111
assert.equal(
1212
comb.processString('a { color: red }'),
1313
'a { color: red }'
1414
);
1515
});
16-
it('True Boolean value should set 1 space after brace', function() {
16+
it('True Boolean value should set 1 space before brace', function() {
1717
comb.configure({ 'stick-brace': true });
1818
assert.equal(
1919
comb.processString('a{color:red }'),
2020
'a {color:red }'
2121
);
2222
});
23-
it('Valid String value should set equal space after brace', function() {
23+
it('Valid Number value should set equal space before brace', function() {
24+
comb.configure({ 'stick-brace': 0 });
25+
assert.equal(
26+
comb.processString('a {color:red }'),
27+
'a{color:red }'
28+
);
29+
});
30+
it('Valid String value should set equal space before brace', function() {
2431
comb.configure({ 'stick-brace': '\n' });
2532
assert.equal(
2633
comb.processString(

0 commit comments

Comments
 (0)