File tree Expand file tree Collapse file tree 3 files changed +88
-2
lines changed
Expand file tree Collapse file tree 3 files changed +88
-2
lines changed Original file line number Diff line number Diff line change @@ -85,9 +85,11 @@ a { color: red }
8585# ## colon-space
8686Available values:
8787 * ` {Boolean}` true (means ` after` )
88- * ` {String}` : ` before` , ` after` or ` both`
88+ * ` {String}` : ` before` , ` after` , ` both` or any combination of whitespaces
89+ and/or a colon (` ` , ` : ` , ` \t :\n\t ` etc.)
8990
9091Example: ` { " colon-space" : true }`
92+
9193` ` ` css
9294/* before * /
9395a { color:red }
@@ -96,6 +98,31 @@ a { color:red }
9698a { color: red }
9799` ` `
98100
101+ Example: ` { " colon-space" : " :\n\t\t" }`
102+
103+ ` ` ` css
104+ /* before * /
105+ a {
106+ color: red;
107+ }
108+
109+ /* after * /
110+ a {
111+ color:
112+ red;
113+ }
114+ ` ` `
115+
116+ Example: ` { " colon-space" : " :" }`
117+
118+ ` ` ` css
119+ /* before * /
120+ a { color: red }
121+
122+ /* after * /
123+ a { color:red }
124+ ` ` `
125+
99126# # Tests
100127
101128Run ` npm test` for tests.
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ module.exports = {
99 setValue : function ( value ) {
1010 this . _value = false ;
1111 if ( value === true ) this . _value = 'after' ;
12- 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 ( typeof value === 'string' && value . match ( / a f t e r | b e f o r e | b o t h | (? = .* (?: [ \t \n ] | : ) ) [ \t \n ] * : ? [ \t \n ] * / ) ) {
13+ this . _value = value ;
14+ }
1315 if ( ! this . _value ) return ;
1416 return this ;
1517 } ,
@@ -20,15 +22,20 @@ module.exports = {
2022 * @param {node } node
2123 */
2224 process : function ( nodeType , node ) {
25+ var detectSpaces = this . _value . match ( / ( ( [ \t \n ] * ) : ) ? ( [ \t \n ] * ) / ) ;
2326 if ( nodeType === 'property' ) {
2427 if ( node [ node . length - 1 ] [ 0 ] === 's' ) node . pop ( ) ;
2528 if ( this . _value === 'both' || this . _value === 'before' )
2629 node . push ( [ 's' , ' ' ] ) ;
30+ if ( detectSpaces && detectSpaces [ 1 ] )
31+ node . push ( [ 's' , detectSpaces [ 2 ] ] ) ;
2732 }
2833 if ( nodeType === 'value' ) {
2934 if ( node [ 0 ] [ 0 ] === 's' ) node . shift ( ) ;
3035 if ( this . _value === 'both' || this . _value === 'after' )
3136 node . unshift ( [ 's' , ' ' ] ) ;
37+ if ( detectSpaces )
38+ node . unshift ( [ 's' , detectSpaces [ 3 ] ] ) ;
3239 }
3340 }
3441
Original file line number Diff line number Diff line change @@ -77,4 +77,56 @@ describe('options/colon-space', function() {
7777 'a {color : red}'
7878 ) ;
7979 } ) ;
80+ it ( '` ` value should set two spaces after colon' , function ( ) {
81+ comb . configure ( { 'colon-space' : ' ' } ) ;
82+ assert . equal (
83+ comb . processString (
84+ 'a { color: red }' +
85+ 'a{color:red}' +
86+ 'a {color : red}'
87+ ) ,
88+ 'a { color: red }' +
89+ 'a{color: red}' +
90+ 'a {color: red}'
91+ ) ;
92+ } ) ;
93+ it ( '`:` value should set no space around colon' , function ( ) {
94+ comb . configure ( { 'colon-space' : ':' } ) ;
95+ assert . equal (
96+ comb . processString (
97+ 'a { color: red }' +
98+ 'a{color:red}' +
99+ 'a {color : red}'
100+ ) ,
101+ 'a { color:red }' +
102+ 'a{color:red}' +
103+ 'a {color:red}'
104+ ) ;
105+ } ) ;
106+ it ( '`\n:` value should set a newline before colon' , function ( ) {
107+ comb . configure ( { 'colon-space' : '\n:' } ) ;
108+ assert . equal (
109+ comb . processString (
110+ 'a { color: red }' +
111+ 'a{color:red}' +
112+ 'a {color : red}'
113+ ) ,
114+ 'a { color\n:red }' +
115+ 'a{color\n:red}' +
116+ 'a {color\n:red}'
117+ ) ;
118+ } ) ;
119+ it ( '`\t:\t` value should set tabs around colon' , function ( ) {
120+ comb . configure ( { 'colon-space' : '\t:\t' } ) ;
121+ assert . equal (
122+ comb . processString (
123+ 'a { color: red }' +
124+ 'a{color:red}' +
125+ 'a {color : red}'
126+ ) ,
127+ 'a { color\t:\tred }' +
128+ 'a{color\t:\tred}' +
129+ 'a {color\t:\tred}'
130+ ) ;
131+ } ) ;
80132} ) ;
You can’t perform that action at this time.
0 commit comments