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-opening-brace
- Loading branch information
Showing
9 changed files
with
185 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,43 @@ | ||
module.exports = { | ||
name: 'space-after-opening-brace', | ||
|
||
accepts: { | ||
number: true, | ||
string: /^[ \t\n]*$/ | ||
}, | ||
|
||
/** | ||
* Processes tree node. | ||
* | ||
* @param {String} nodeType | ||
* @param {node} node | ||
*/ | ||
process: function(nodeType, node) { | ||
// If found block node stop at the next one for space check | ||
if (nodeType !== 'block' && nodeType !== 'atrulers') return; | ||
|
||
var value = this.getValue('space-after-opening-brace'); | ||
|
||
if (node[0][0] === 's') { | ||
node[0][1] = value; | ||
} else 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 !== 'block' && nodeType !== 'atrulers') 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,84 @@ | ||
describe('options/space-after-opening-brace:', function() { | ||
beforeEach(function() { | ||
this.filename = __filename; | ||
}); | ||
|
||
it('Array value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-opening-brace': ['', ' '] }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Invalid string value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-opening-brace': ' nani ' }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Float number value => should not change anything', function() { | ||
this.comb.configure({ 'space-after-opening-brace': 3.5 }); | ||
this.shouldBeEqual('test.css'); | ||
}); | ||
|
||
it('Integer value => should set proper space after {', function() { | ||
this.comb.configure({ 'space-after-opening-brace': 0 }); | ||
this.shouldBeEqual('test.css', 'test.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces only) => should set proper space after {', function() { | ||
this.comb.configure({ 'space-after-opening-brace': ' ' }); | ||
this.shouldBeEqual('test.css', 'test-2.expected.css'); | ||
}); | ||
|
||
it('Valid string value (spaces and newlines) => should set proper space after {', function() { | ||
this.comb.configure({ 'space-after-opening-brace': '\n ' }); | ||
this.shouldBeEqual('test.css', 'test-3.expected.css'); | ||
}); | ||
|
||
it('Should detect no whitespace', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{top:0}', | ||
{ 'space-after-opening-brace': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{\n\ttop:0}', | ||
{ 'space-after-opening-brace': '\n\t' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespace (2 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{top:0} b{\n left:0}', | ||
{ 'space-after-opening-brace': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace (2 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{ top:0 } b{left:0}', | ||
{ 'space-after-opening-brace': ' ' } | ||
); | ||
}); | ||
|
||
it('Should detect no whitespace (3 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{top:0} b { left: 0 } c{\n\tright:0}', | ||
{ 'space-after-opening-brace': '' } | ||
); | ||
}); | ||
|
||
it('Should detect whitespace (3 blocks)', function() { | ||
this.shouldDetect( | ||
['space-after-opening-brace'], | ||
'a{\ntop:0} b{\nleft:0} c{\n right:0}', | ||
{ 'space-after-opening-brace': '\n' } | ||
); | ||
}); | ||
}); | ||
|
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{ top: 0} | ||
a { top: 0 } | ||
|
||
@media print{ a{ top: 0}} | ||
@media print { a { top: 0 } } |
11 changes: 11 additions & 0 deletions
11
test/options/space-after-opening-brace/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{ | ||
top: 0} | ||
a { | ||
top: 0 } | ||
|
||
@media print{ | ||
a{ | ||
top: 0}} | ||
@media print { | ||
a { | ||
top: 0 } } |
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{top: 0} | ||
a { top: 0 } | ||
|
||
@media print{a{top: 0}} | ||
@media print { a { top: 0 } } |
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{top: 0} | ||
a {top: 0 } | ||
|
||
@media print{a{top: 0}} | ||
@media print {a {top: 0 } } |