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.
New option: space-after-selector-delimiter
- Loading branch information
Showing
9 changed files
with
242 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,54 @@ | ||
module.exports = { | ||
name: 'space-after-selector-delimiter', | ||
|
||
accepts: { | ||
number: true, | ||
string: /^[ \t\n]*$/ | ||
}, | ||
|
||
/** | ||
* Processes tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
process: function(nodeType, node) { | ||
if (nodeType !== 'selector') return; | ||
|
||
var value = this.getValue('space-after-selector-delimiter'); | ||
|
||
for (var i = node.length; i--;) { | ||
if (node[i][0] === 'delim') { | ||
if (node[i + 1][1][0] === 's') { | ||
node[i + 1][1][1] = value; | ||
} else { | ||
node[i + 1].splice(1, 0, ['s', value]); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
/** | ||
* Detects the value of an option at the tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
detect: function(nodeType, node) { | ||
if (nodeType !== 'selector') return; | ||
|
||
var variants = []; | ||
|
||
for (var i = node.length; i--;) { | ||
if (node[i][0] !== 'delim') continue; | ||
|
||
if (node[i + 1][1][0] === 's') { | ||
variants.push(node[i + 1][1][1]); | ||
} else { | ||
variants.push(''); | ||
} | ||
} | ||
|
||
return variants; | ||
} | ||
}; |
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,83 @@ | ||
describe('options/space-after-selector-delimiter:', function() { | ||
beforeEach(function() { | ||
this.filename = __filename; | ||
}); | ||
|
||
it('Array value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': ['', ' '] }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Invalid string value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': ' nani ' }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Float number value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': 3.5 }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Integer value => should set proper space after selector delimiter', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': 0 }); | ||
this.shouldBeEqual('test.css', 'test.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces only) => should set proper space after selector delimiter', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': ' ' }); | ||
this.shouldBeEqual('test.css', 'test-2.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces and newlines) => should set proper space after selector delimiter', function() { | ||
this.comb.configure({ 'space-after-selector-delimiter': '\n ' }); | ||
this.shouldBeEqual('test.css', 'test-3.expected.css'); | ||
}); | ||
|
||
it('Should detect no whitespace', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a,b{top:0}', | ||
{ 'space-after-selector-delimiter': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a, \n b {top:0}', | ||
{ 'space-after-selector-delimiter': ' \n ' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespace (2 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a,b{top:0} a, b{left:0}', | ||
{ 'space-after-selector-delimiter': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace (2 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a, b {top:0} b,a{left:0}', | ||
{ 'space-after-selector-delimiter': ' ' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespace (3 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a, b{top:0} b,c{left:0} c,d{right:0}', | ||
{ 'space-after-selector-delimiter': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace (3 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-selector-delimiter'], | ||
'a,b{top:0} b, c{left:0} c, sd{right:0}', | ||
{ 'space-after-selector-delimiter': ' ' } | ||
); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
test/options/space-after-selector-delimiter/test-2.expected.css
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, b { color: red } | ||
a, b { color: red } | ||
a , b { color: red } | ||
a, b { color: red } | ||
a+b, c>d, e{ color: red } |
11 changes: 11 additions & 0 deletions
11
test/options/space-after-selector-delimiter/test-3.expected.css
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,11 @@ | ||
a, | ||
b { color: red } | ||
a, | ||
b { color: red } | ||
a , | ||
b { color: red } | ||
a, | ||
b { color: red } | ||
a+b, | ||
c>d, | ||
e{ color: 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,6 @@ | ||
a,b { color: red } | ||
a, b { color: red } | ||
a ,b { color: red } | ||
a, | ||
b { color: red } | ||
a+b,c>d,e{ color: red } |
5 changes: 5 additions & 0 deletions
5
test/options/space-after-selector-delimiter/test.expected.css
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,b { color: red } | ||
a,b { color: red } | ||
a ,b { color: red } | ||
a,b { color: red } | ||
a+b,c>d,e{ color: red } |