Skip to content

Commit 106bb70

Browse files
committed
Merge pull request #126 from csscomb/tg/116-consistent-values
Change acceptable values (#116)
2 parents e792f82 + 2b6ea64 commit 106bb70

12 files changed

Lines changed: 242 additions & 377 deletions

.csscomb.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
"node_modules/**"
55
],
66
"always-semicolon": true,
7-
"block-indent": true,
8-
"colon-space": true,
7+
"block-indent": " ",
8+
"colon-space": ["", " "],
99
"color-case": "lower",
1010
"color-shorthand": true,
11-
"combinator-space": true,
11+
"combinator-space": [" ", " "],
1212
"element-case": "lower",
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: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,16 @@ Example configuration:
149149
"verbose": true,
150150

151151
"always-semicolon": true,
152-
"block-indent": true,
153-
"colon-space": true,
152+
"block-indent": " ",
153+
"colon-space": ["", " "],
154154
"color-case": "lower",
155155
"color-shorthand": true,
156156
"element-case": "lower",
157157
"eof-newline": true,
158158
"leading-zero": false,
159159
"remove-empty-rulesets": true,
160-
"rule-indent": true,
161-
"stick-brace": true,
160+
"rule-indent": " ",
161+
"stick-brace": "\n",
162162
"strip-spaces": true,
163163
"unitless-zero": true,
164164
"vendor-prefix-align": 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,59 +351,54 @@ a { color: red
351351
}
352352
```
353353
354-
### colon-space
355-
356-
Available values:
357-
* `{Boolean}` `true` (means `after`) or `false` (no whitespace at all)
358-
* `{String}`: `before`, `after`, `both` or any combination of whitespaces
359-
and/or a colon (` `, `: `, `\t:\n\t` etc.)
360-
* `{Array}` with two `{String}` values: for setting left and right whitespace around a colon
361-
362-
Example: `{ "colon-space": true }`
354+
Example: `{ "block-indent": " " }`
363355
364356
```css
365357
/* before */
366-
a { color:red }
358+
a { color: red }
359+
@media all { a { color: green } }
367360
368361
/* after */
369-
a { color: red }
362+
a { color: red
363+
}
364+
@media all {
365+
a { color: green
366+
}
367+
}
370368
```
371369
372-
Example: `{ "colon-space": ":\n\t\t" }`
373370
374-
```css
375-
/* before */
376-
a {
377-
color: red;
378-
}
371+
### colon-space
379372
380-
/* after */
381-
a {
382-
color:
383-
red;
384-
}
385-
```
373+
Acceptable value is `{Array}` with 2 elements of following types:
374+
* `{Number}` of spaces;
375+
* `{String}` of whitespaces or tabs. If there is any other character in the
376+
string, the value will not be set.
386377
387-
Example: `{ "colon-space": "" }`
378+
The first element of the array sets spaces before colon, and the second one sets
379+
spaces after colon.
380+
381+
Example: `{ "colon-space": ["\t", "\t"] }`
388382
389383
```css
390384
/* before */
391385
a { color: red }
392386
393387
/* after */
394-
a { color:red }
388+
a { color : red }
395389
```
396390
397-
Example: `{ "colon-space": ["\t", "\t"] }`
391+
Example: `{ "colon-space": [0, 1] }`
398392
399393
```css
400394
/* before */
401-
a { color: red }
395+
a { color:red }
402396
403397
/* after */
404-
a { color : red }
398+
a { color: red }
405399
```
406400
401+
407402
### color-case
408403
409404
Available values: `{String}` `lower` or `upper`
@@ -434,42 +429,36 @@ b { color: #fc0 }
434429
435430
### combinator-space
436431
437-
Available values:
438-
* `{Boolean}`: `true` sets one space, `false` removes the spaces.
439-
* `{String}`: any combination of whitespaces.
440-
* `{Array}` with two `{String}` values: for setting left and right whitespace.
441-
442-
Example: `{ "combinator-space": true }`
443-
444-
```css
445-
/* before */
446-
a>b { color: red }
432+
Acceptable value is `{Array}` with 2 elements of following types:
433+
* `{Number}` of spaces;
434+
* `{String}` of whitespaces, tabs or new lines. If there is any other
435+
character in the string, the value will not be set.
447436
448-
/* after */
449-
a > b { color: red }
450-
```
437+
The first element of the array sets spaces before combinator, and the second
438+
one sets spaces after combinator.
451439
452-
Example: `{ "combinator-space": "" }`
440+
Example: `{ "combinator-space": [" ", "\n"] }`
453441
454442
```css
455443
/* before */
456-
a > b { color: red }
444+
a>b { color: red }
457445
458446
/* after */
459-
a>b { color: red }
447+
a >
448+
b { color: red }
460449
```
461450
462-
Example: `{ "combinator-space": [" ", "\n"] }`
451+
Example: `{ "combinator-space": [1, 1] }`
463452
464453
```css
465454
/* before */
466455
a>b { color: red }
467456
468457
/* after */
469-
a >
470-
b { color: red }
458+
a > b { color: red }
471459
```
472460
461+
473462
### element-case
474463
475464
Available values: `{String}` `lower` or `upper`
@@ -522,10 +511,10 @@ Example: `{ "remove-empty-rulesets": true }` - remove rulesets that have no decl
522511
523512
**Note**: better to use with [block-indent](#block-indent)
524513
525-
Available values:
526-
* `{Boolean}` `true` (means 4 spaces)
527-
* `{Number}` of spaces
528-
* `{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.
529518
530519
Example: `{ "rule-indent": 2 }`
531520
@@ -539,6 +528,19 @@ a {
539528
margin:0 }
540529
```
541530
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+
542544
### sort-order
543545
544546
**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
@@ -615,10 +617,10 @@ p {
615617
616618
### stick-brace
617619
618-
Available values:
619-
* `{Boolean}` `true` (means 1 space)
620-
* `{Number}` of spaces
621-
* `{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.
622624
623625
Example: `{ "stick-brace": "\n" }`
624626
@@ -631,6 +633,17 @@ a
631633
{ color:red }
632634
```
633635
636+
Example: `{ "stick-brace": 1 }`
637+
638+
```css
639+
/* before */
640+
a{ color:red }
641+
642+
/* after */
643+
a { color:red }
644+
```
645+
646+
634647
### strip-spaces
635648
636649
Available value: `{Boolean}` `true`

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

lib/options/colon-space.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,31 @@ module.exports = {
33
/**
44
* Sets handler value.
55
*
6-
* @param {String|Boolean} value Option value
6+
* @param {Array} value Option value
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true)
12-
value = 'after';
13-
if (value === false)
14-
value = '';
15-
if (value === 'both')
16-
this._value = [' ', ' '];
17-
if (value === 'before')
18-
this._value = [' ', ''];
19-
if (value === 'after')
20-
this._value = ['', ' '];
21-
if (value.constructor === Array && value[0].match(/^[ \t]*$/) && value[1].match(/^[ \t]*$/))
22-
this._value = value;
23-
if (typeof value === 'string') {
24-
if (value.match(/^[ \t]*$/)) {
25-
this._value = ['', value];
26-
} else {
27-
var detectSpaces = value.match(/^(([ \t]*):)?([ \t]*)$/);
28-
if (detectSpaces) {
29-
if (detectSpaces[1]) {
30-
this._value = [detectSpaces[2], detectSpaces[3]];
31-
} else {
32-
this._value = ['', detectSpaces[3]];
33-
}
34-
}
35-
}
10+
delete this._value;
11+
12+
if (value.constructor !== Array) return;
13+
14+
if (typeof value[0] === 'number' &&
15+
value[0] === Math.abs(Math.round(value[0]))) {
16+
value[0] = new Array(value[0] + 1).join(' ');
17+
} else if (typeof value[0] !== 'string' ||
18+
!value[0].match(/^[ \t\n]*$/)) {
19+
return;
20+
}
21+
22+
if (typeof value[1] === 'number' &&
23+
value[1] === Math.abs(Math.round(value[1]))) {
24+
value[1] = new Array(value[1] + 1).join(' ');
25+
} else if (typeof value[1] !== 'string' ||
26+
!value[1].match(/^[ \t\n]*$/)) {
27+
return;
3628
}
3729

38-
if (!this._value) return;
30+
this._value = value;
3931
return this;
4032
},
4133

lib/options/combinator-space.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,33 @@ module.exports = {
33
/**
44
* Sets handler value.
55
*
6-
* @param {String|Boolean|Array} value Option value
7-
* @returns {Object}
6+
* @param {Array} value Option value
7+
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = ' ';
12-
if (value === false) value = '';
13-
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) {
14-
this._value = [value, value];
10+
delete this._value;
11+
12+
if (value.constructor !== Array) return;
13+
14+
if (typeof value[0] === 'number' &&
15+
value[0] === Math.abs(Math.round(value[0]))) {
16+
value[0] = new Array(value[0] + 1).join(' ');
17+
} else if (typeof value[0] !== 'string' ||
18+
!value[0].match(/^[ \t\n]*$/)) {
19+
return;
1520
}
16-
if (value.constructor === Array) this._value = value;
17-
if (!this._value) return;
21+
22+
if (typeof value[1] === 'number' &&
23+
value[1] === Math.abs(Math.round(value[1]))) {
24+
value[1] = new Array(value[1] + 1).join(' ');
25+
} else if (typeof value[1] !== 'string' ||
26+
!value[1].match(/^[ \t\n]*$/)) {
27+
return;
28+
}
29+
30+
this._value = value;
1831
return this;
32+
1933
},
2034

2135
/**

0 commit comments

Comments
 (0)