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
176 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,40 @@ | ||
module.exports = { | ||
name: 'space-before-colon', | ||
|
||
accepts: { | ||
number: true, | ||
string: /^[ \t\n]*$/ | ||
}, | ||
|
||
/** | ||
* Processes tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
process: function(nodeType, node) { | ||
if (nodeType !== 'property') return; | ||
|
||
var value = this.getValue('space-before-colon'); | ||
|
||
if (node[node.length - 1][0] === 's') node.pop(); | ||
if (value !== '') node.push(['s', value]); | ||
}, | ||
|
||
/** | ||
* Detects the value of an option at the tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
detect: function(nodeType, node) { | ||
if (nodeType !== 'property') return; | ||
|
||
var lastNode = node[node.length - 1]; | ||
if (lastNode[0] === 's') { | ||
return lastNode[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-before-colon:', function() { | ||
beforeEach(function() { | ||
this.filename = __filename; | ||
}); | ||
|
||
it('Array value => should not change anything', function() { | ||
this.comb.configure({ 'space-before-colon': ['', ' '] }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Invalid string value => should not change anything', function() { | ||
this.comb.configure({ 'space-before-colon': ' nani ' }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Float number value => should not change anything', function() { | ||
this.comb.configure({ 'space-before-colon': 3.5 }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Integer value => should set proper space before colon', function() { | ||
this.comb.configure({ 'space-before-colon': 0 }); | ||
this.shouldBeEqual('test.css', 'test.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces only) => should set proper space before colon', function() { | ||
this.comb.configure({ 'space-before-colon': ' ' }); | ||
this.shouldBeEqual('test.css', 'test-2.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces and newlines) => should set proper space before colon', function() { | ||
this.comb.configure({ 'space-before-colon': '\n ' }); | ||
this.shouldBeEqual('test.css', 'test-3.expected.css'); | ||
}); | ||
|
||
it('Should detect no whitespaces', function() { | ||
this.shouldDetect( | ||
['space-before-colon'], | ||
'a { color:red }', | ||
{ 'space-before-colon': '' } | ||
); | ||
}); | ||
|
||
it('Should detect no space from two variants', function() { | ||
this.shouldDetect( | ||
['space-before-colon'], | ||
'a { color: red; color :red }', | ||
{ 'space-before-colon': '' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespaces along three variants', function() { | ||
this.shouldDetect( | ||
['space-before-colon'], | ||
'a { color: red; background :red } b { width:10px }', | ||
{ 'space-before-colon': '' } | ||
); | ||
}); | ||
|
||
it('Should detect space', function() { | ||
this.shouldDetect( | ||
['space-before-colon'], | ||
'a { color : red; background :red } b { width:10px }', | ||
{ 'space-before-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 } |