File tree Expand file tree Collapse file tree 8 files changed +152
-20
lines changed
Expand file tree Collapse file tree 8 files changed +152
-20
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ Comb.prototype = {
3232 for ( var option in config ) {
3333 if ( config . hasOwnProperty ( option ) && config [ option ] && this . _options [ option ] ) {
3434 try {
35- this . _config [ option ] = require ( './options/' + option ) . setValue ( config [ option ] ) ;
35+ var handler = require ( './options/' + option ) . setValue ( config [ option ] ) ;
36+ if ( handler ) this . _config [ option ] = handler ;
3637 } catch ( e ) { }
3738 }
3839 }
@@ -84,7 +85,7 @@ Comb.prototype = {
8485 } catch ( e ) {
8586 throw new Error ( 'Parsing error at ' + filename + ': ' + e . message ) ;
8687 }
87- return cssp . translate ( cssp . transform ( tree ) ) ;
88+ return cssp . translate ( tree ) ;
8889 } ,
8990
9091 /**
Original file line number Diff line number Diff line change 11module . exports = {
22
3- _value : false ,
4-
53 /**
64 * Sets handler value.
75 *
86 * @param {String|Boolean } value Option value
97 * @returns {Object }
108 */
119 setValue : function ( value ) {
12- if ( ! value ) return this ;
13- if ( typeof value === 'string' ) {
14- this . _value = value ;
15- } else {
16- this . _value = 'after' ; // default
17- }
10+ if ( value === true ) this . _value = 'after' ;
11+ if ( typeof value === 'string' && value . match ( / a f t e r | b e f o r e | b o t h / ) ) this . _value = value ;
12+ if ( ! this . _value ) return ;
1813 return this ;
1914 } ,
2015
Original file line number Diff line number Diff line change 11module . exports = {
22
3- _value : false ,
4-
53 /**
64 * Sets handler value.
75 *
86 * @param {String|Number|Boolean } value Option value
97 * @returns {Object }
108 */
119 setValue : function ( value ) {
12- if ( ! value ) return this ;
13- if ( value === true ) value = ' ' ; // 1 space by default
14- if ( typeof value === 'number' ) this . _value = new Array ( Math . round ( value ) + 1 ) . join ( ' ' ) ;
10+ if ( value === true ) value = ' ' ;
1511 if ( typeof value === 'string' && value . match ( / ^ [ \t \n ] * $ / ) ) this . _value = value ;
12+ if ( ! this . _value ) return ;
1613 return this ;
1714 } ,
1815
Original file line number Diff line number Diff line change 11module . exports = {
22
3- value : false ,
4-
53 /**
64 * Sets handler value.
75 *
86 * @param {String|Boolean } value Option value
97 * @returns {Object }
108 */
119 setValue : function ( value ) {
12- this . _value = Boolean ( value ) ;
10+ this . _value = value === true ;
11+ if ( ! this . _value ) return ;
1312 return this ;
1413 } ,
1514
Original file line number Diff line number Diff line change 3030 "devDependencies" : {
3131 "jshint-groups" : " 0.5.1" ,
3232 "jshint" : " 2.1.7" ,
33- "jscs" : " 1.0.2"
33+ "jscs" : " 1.0.2" ,
34+ "mocha" : " 1.11.0"
3435 },
3536 "bin" : {
3637 "csscomb" : " ./bin/csscomb"
3738 },
3839 "scripts" : {
39- "test" : " ./node_modules/.bin/jshint-groups; . /node_modules/.bin/jscs ."
40+ "test" : " ./node_modules/.bin/jshint-groups . && . /node_modules/.bin/jscs . && ./node_modules/.bin/mocha -u bdd -R spec "
4041 }
4142}
Original file line number Diff line number Diff line change 1+ var Comb = require ( '../lib/csscomb' ) ;
2+ var assert = require ( 'assert' ) ;
3+
4+ describe ( 'options/colon-space' , function ( ) {
5+ var comb ;
6+ beforeEach ( function ( ) {
7+ comb = new Comb ( ) ;
8+ } ) ;
9+ it ( 'Invalid String should not change space around colon' , function ( ) {
10+ comb . configure ( { 'colon-space' : 'foobar' } ) ;
11+ assert . equal (
12+ comb . processString ( 'a { color: red }' ) ,
13+ 'a { color: red }'
14+ ) ;
15+ } ) ;
16+ it ( 'True Boolean value should set space after colon' , function ( ) {
17+ comb . configure ( { 'colon-space' : true } ) ;
18+ assert . equal (
19+ comb . processString (
20+ 'a { color: red }\n' +
21+ 'b{color:blue}\n' +
22+ 'i {font : 0/0 a}'
23+ ) ,
24+ 'a { color: red }\n' +
25+ 'b{color: blue}\n' +
26+ 'i {font: 0/0 a}'
27+ ) ;
28+ } ) ;
29+ it ( '`before` value should set space before colon' , function ( ) {
30+ comb . configure ( { 'colon-space' : 'before' } ) ;
31+ assert . equal (
32+ comb . processString (
33+ 'a { color: red }\n' +
34+ 'b{color:blue}\n' +
35+ 'i {font : 0/0 a}'
36+ ) ,
37+ 'a { color :red }\n' +
38+ 'b{color :blue}\n' +
39+ 'i {font :0/0 a}'
40+ ) ;
41+ } ) ;
42+ it ( '`after` value should set space before colon' , function ( ) {
43+ comb . configure ( { 'colon-space' : 'after' } ) ;
44+ assert . equal (
45+ comb . processString (
46+ 'a { color: red }\n' +
47+ 'b{color:blue}\n' +
48+ 'i {font : 0/0 a}'
49+ ) ,
50+ 'a { color: red }\n' +
51+ 'b{color: blue}\n' +
52+ 'i {font: 0/0 a}'
53+ ) ;
54+ } ) ;
55+ it ( '`both` value should set spaces around colon' , function ( ) {
56+ comb . configure ( { 'colon-space' : 'both' } ) ;
57+ assert . equal (
58+ comb . processString (
59+ 'a { color: red }\n' +
60+ 'b{color:blue}\n' +
61+ 'i {font : 0/0 a}'
62+ ) ,
63+ 'a { color : red }\n' +
64+ 'b{color : blue}\n' +
65+ 'i {font : 0/0 a}'
66+ ) ;
67+ } ) ;
68+ } ) ;
Original file line number Diff line number Diff line change 1+ var Comb = require ( '../lib/csscomb' ) ;
2+ var assert = require ( 'assert' ) ;
3+
4+ describe ( 'options/stick-brace' , function ( ) {
5+ var comb ;
6+ beforeEach ( function ( ) {
7+ comb = new Comb ( ) ;
8+ } ) ;
9+ it ( 'Invalid String should not change space after brace' , function ( ) {
10+ comb . configure ( { 'stick-brace' : 'foobar' } ) ;
11+ assert . equal (
12+ comb . processString ( 'a { color: red }' ) ,
13+ 'a { color: red }'
14+ ) ;
15+ } ) ;
16+ it ( 'True Boolean value should set 1 space after brace' , function ( ) {
17+ comb . configure ( { 'stick-brace' : true } ) ;
18+ assert . equal (
19+ comb . processString (
20+ 'a { color: red }\n' +
21+ 'b{color:blue}\n' +
22+ 'i \t\t \n{font:0/0 a}'
23+ ) ,
24+ 'a { color: red }\n' +
25+ 'b {color:blue}\n' +
26+ 'i {font:0/0 a}'
27+ ) ;
28+ } ) ;
29+ it ( 'Valid String value should set equal space after brace' , function ( ) {
30+ comb . configure ( { 'stick-brace' : '\n' } ) ;
31+ assert . equal (
32+ comb . processString (
33+ 'a { color: red }\n' +
34+ 'b{color:blue}\n' +
35+ 'i \t\t \n{font:0/0 a}'
36+ ) ,
37+ 'a\n{ color: red }\n' +
38+ 'b\n{color:blue}\n' +
39+ 'i\n{font:0/0 a}'
40+ ) ;
41+ } ) ;
42+ } ) ;
Original file line number Diff line number Diff line change 1+ var Comb = require ( '../lib/csscomb' ) ;
2+ var assert = require ( 'assert' ) ;
3+
4+ describe ( 'options/strip-space' , function ( ) {
5+ var comb ;
6+ beforeEach ( function ( ) {
7+ comb = new Comb ( ) ;
8+ } ) ;
9+ it ( 'Invalid value should not change trim trailing brace' , function ( ) {
10+ comb . configure ( { 'strip-spaces' : 'foobar' } ) ;
11+ assert . equal (
12+ comb . processString ( 'a { color: red }' ) ,
13+ 'a { color: red }'
14+ ) ;
15+ } ) ;
16+ it ( 'True Boolean value should trim all trailing spaces' , function ( ) {
17+ comb . configure ( { 'strip-spaces' : true } ) ;
18+ assert . equal (
19+ comb . processString (
20+ 'a { color: red } \n' +
21+ 'b{color:blue}\t \n' +
22+ 'i {font:0/0 a}'
23+ ) ,
24+ 'a { color: red }\n' +
25+ 'b{color:blue}\n' +
26+ 'i {font:0/0 a}\n'
27+ ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments