Skip to content

Commit d39942e

Browse files
committed
Gonzales 3.0: Update unitless-zero option
1 parent a848aa3 commit d39942e

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

lib/options/unitless-zero.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ module.exports = {
77

88
/**
99
* Processes tree node.
10-
* @param {String} nodeType
10+
*
1111
* @param {node} node
1212
*/
13-
process: function(nodeType, node) {
14-
if (nodeType === 'value' || nodeType === 'braces') {
15-
node.forEach(function(child, index) {
16-
if (
17-
(child[0] === 'percentage' ||
18-
child[0] === 'dimension' && ['cm', 'em', 'ex', 'pt', 'px'].indexOf(child[2][1]) !== -1) &&
19-
child[1][1] === '0') {
20-
node[index] = child[1];
13+
process: function(node) {
14+
var UNITS = ['cm', 'em', 'ex', 'pt', 'px'];
15+
16+
if (node.is('value') || node.is('braces')) {
17+
node.forEach(function(child) {
18+
if (typeof child === 'string') return;
19+
20+
if (child.is('dimension')) {
21+
var unit = child.get(1).content;
22+
if (child.get(0).content[0] === '0' && UNITS.indexOf(unit) !== -1) {
23+
child.content.splice(1, 1);
24+
}
25+
} else if (child.is('percentage')) {
26+
var number = child.get(0).content;
27+
if (number[0] === '0') {
28+
child.type = 'number';
29+
child.content = number;
30+
}
2131
}
2232
});
2333
}

test/options/unitless-zero/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var assert = require('assert');
22

3-
describe.skip('options/unitless-zero', function() {
3+
describe('options/unitless-zero', function() {
44
it('Should remove units in zero-valued dimensions', function() {
55
this.comb.configure({ 'unitless-zero': true });
66
assert.equal(
@@ -35,7 +35,7 @@ describe.skip('options/unitless-zero', function() {
3535
);
3636
});
3737

38-
it('Should detect unitless zero option', function() {
38+
it.skip('Should detect unitless zero option', function() {
3939
this.shouldDetect(
4040
['unitless-zero'],
4141
'a { width: 0 }',
@@ -45,7 +45,7 @@ describe.skip('options/unitless-zero', function() {
4545
);
4646
});
4747

48-
it('Should detect zero with unit', function() {
48+
it.skip('Should detect zero with unit', function() {
4949
this.shouldDetect(
5050
['unitless-zero'],
5151
'a { width: 0px }',
@@ -55,7 +55,7 @@ describe.skip('options/unitless-zero', function() {
5555
);
5656
});
5757

58-
it('Should detect unitless zero option with multiple values', function() {
58+
it.skip('Should detect unitless zero option with multiple values', function() {
5959
this.shouldDetect(
6060
['unitless-zero'],
6161
'a { padding: 0px 0 0 }',
@@ -65,7 +65,7 @@ describe.skip('options/unitless-zero', function() {
6565
);
6666
});
6767

68-
it('Should detect zero with unit and multiple values', function() {
68+
it.skip('Should detect zero with unit and multiple values', function() {
6969
this.shouldDetect(
7070
['unitless-zero'],
7171
'a { padding: 0px 0 0em }',
@@ -75,23 +75,23 @@ describe.skip('options/unitless-zero', function() {
7575
);
7676
});
7777

78-
it('Shouldn’t detect unitless zero option if there is no unit', function() {
78+
it.skip('Shouldn’t detect unitless zero option if there is no unit', function() {
7979
this.shouldDetect(
8080
['unitless-zero'],
8181
'a { color: red }',
8282
{}
8383
);
8484
});
8585

86-
it('Shouldn’t detect unitless zero option if there is `deg` unit', function() {
86+
it.skip('Shouldn’t detect unitless zero option if there is `deg` unit', function() {
8787
this.shouldDetect(
8888
['unitless-zero'],
8989
'a { transform: rotate(0deg) }',
9090
{}
9191
);
9292
});
9393

94-
it('Should detect unitless zero option with percents', function() {
94+
it.skip('Should detect unitless zero option with percents', function() {
9595
this.shouldDetect(
9696
['unitless-zero'],
9797
'a { padding: 0% 0 0 }',

0 commit comments

Comments
 (0)