forked from csscomb/csscomb.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = { | ||
name: 'space-after-colon', | ||
|
||
accepts: { | ||
number: true, | ||
string: /^[ \t\n]*$/ | ||
}, | ||
|
||
/** | ||
* Processes tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
process: function(nodeType, node) { | ||
if (nodeType !== 'value') return; | ||
|
||
var value = this.getValue('space-after-colon'); | ||
|
||
// Remove any spaces after colon: | ||
if (node[0][0] === 's') node.shift(); | ||
// If the value set in config is not empty, add spaces: | ||
if (value !== '') node.unshift(['s', value]); | ||
}, | ||
|
||
/** | ||
* Detects the value of an option at the tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
detect: function(nodeType, node) { | ||
if (nodeType !== 'value') return; | ||
|
||
if (node[0][0] === 's') { | ||
return node[0][1]; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
describe('options/space-after-colon:', function() { | ||
beforeEach(function() { | ||
this.filename = __filename; | ||
}); | ||
|
||
it('Array value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-colon': ['', ' '] }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Invalid string value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-colon': ' nani ' }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Float number value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-colon': 3.5 }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Integer value => should set proper space after colon', function() { | ||
this.comb.configure({ 'space-after-colon': 0 }); | ||
this.shouldBeEqual('test.css', 'test.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces only)=> should set proper space after colon', function() { | ||
this.comb.configure({ 'space-after-colon': ' ' }); | ||
this.shouldBeEqual('test.css', 'test-2.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spacesand newlines)=> should set proper space after colon', function() { | ||
this.comb.configure({ 'space-after-colon': '\n ' }); | ||
this.shouldBeEqual('test.css', 'test-3.expected.css'); | ||
}); | ||
|
||
it('Should detect no whitespaces', function() { | ||
this.shouldDetect( | ||
['space-after-colon'], | ||
'a { color:red }', | ||
{ 'space-after-colon': '' } | ||
); | ||
}); | ||
|
||
it('Should detect space from two variants', function() { | ||
this.shouldDetect( | ||
['space-after-colon'], | ||
'a { color: red; color :red }', | ||
{ 'space-after-colon': ' ' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespaces along three variants', function() { | ||
this.shouldDetect( | ||
['space-after-colon'], | ||
'a { color: red; background :red } b { width:10px }', | ||
{ 'space-after-colon': '' } | ||
); | ||
}); | ||
|
||
it('Should detect space', function() { | ||
this.shouldDetect( | ||
['space-after-colon'], | ||
'a { color : red; background :red } b { width: 10px }', | ||
{ 'space-after-colon': ' ' } | ||
); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a { color: red } | ||
a{color: red} | ||
a {color : red} | ||
a {color : /* foo */ red } | ||
a {color /* bar */ : red } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
a { color: | ||
red } | ||
a{color: | ||
red} | ||
a {color : | ||
red} | ||
a {color : | ||
/* foo */ red } | ||
a {color /* bar */ : | ||
red } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a { color: red } | ||
a{color:red} | ||
a {color : red} | ||
a {color : /* foo */ red } | ||
a {color /* bar */ : red } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a { color:red } | ||
a{color:red} | ||
a {color :red} | ||
a {color :/* foo */ red } | ||
a {color /* bar */ :red } |