-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New options: Spaces before and after selector delimiters #196
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,6 +427,44 @@ a{ | |
color: panda;} | ||
``` | ||
|
||
## space-after-selector-delimiter | ||
|
||
Set space after selector delimiter. | ||
|
||
Acceptable values: | ||
|
||
* `{Number}` — number of whitespaces; | ||
* `{String}` — string with whitespaces, tabs or line breaks. | ||
|
||
Example: `{ 'space-after-selector-delimiter': 1 }` | ||
|
||
```scss | ||
// Before: | ||
a,b{ | ||
color: panda; | ||
} | ||
|
||
// After: | ||
a, b { | ||
color: panda; | ||
} | ||
``` | ||
|
||
Example: `{ 'space-before-selector-delimiter': '\n' }` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vecmezoni, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tonyganch, actually |
||
|
||
```scss | ||
// Before: | ||
a, b{ | ||
color: panda; | ||
} | ||
|
||
// After: | ||
a, | ||
b{ | ||
color: panda; | ||
} | ||
``` | ||
|
||
## space-before-colon | ||
|
||
Set space before `:` in declarations. | ||
|
@@ -536,6 +574,44 @@ a | |
} | ||
``` | ||
|
||
## space-before-selector-delimiter | ||
|
||
Set space before selector delimiter. | ||
|
||
Acceptable values: | ||
|
||
* `{Number}` — number of whitespaces; | ||
* `{String}` — string with whitespaces, tabs or line breaks. | ||
|
||
Example: `{ 'space-before-selector-delimiter': 0 }` | ||
|
||
```scss | ||
// Before: | ||
a , b{ | ||
color: panda; | ||
} | ||
|
||
// After: | ||
a, b { | ||
color: panda; | ||
} | ||
``` | ||
|
||
Example: `{ 'space-before-selector-delimiter': '\n' }` | ||
|
||
```scss | ||
// Before: | ||
a, b{ | ||
color: panda; | ||
} | ||
|
||
// After: | ||
a | ||
,b{ | ||
color: panda; | ||
} | ||
``` | ||
|
||
## strip-spaces | ||
|
||
Whether to trim trailing spaces. | ||
|
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') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vecmezoni, the same thing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed 👍 |
||
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; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module.exports = { | ||
name: 'space-before-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-before-selector-delimiter'); | ||
|
||
for (var i = node.length; i--;) { | ||
if (node[i][0] === 'delim') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vecmezoni, I like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed 👍 |
||
if (node[i - 1][node[i - 1].length - 1][0] === 's') { | ||
node[i - 1][node[i - 1].length - 1][1] = value; | ||
} else { | ||
node[i - 1].push(['s', value]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vecmezoni, I think it's a good idea to cache There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made a variable for previous node. |
||
} | ||
} | ||
}, | ||
|
||
/** | ||
* 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][node[i - 1].length - 1][0] === 's') { | ||
variants.push(node[i - 1][node[i - 1].length - 1][1]); | ||
} else { | ||
variants.push(''); | ||
} | ||
} | ||
|
||
return variants; | ||
} | ||
}; |
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': ' ' } | ||
); | ||
}); | ||
}); |
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 } |
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 } |
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 } |
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mishanga, I need your opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonyganch, it might be
I just followed my company styleguide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it as it already is.