Skip to content

Commit 0a63b4e

Browse files
tonyganchhaoqunjiang
authored andcommitted
Fix #394: unitless-zero vs fractions
Don't remove units from values starting from zero, like `0.5em`
1 parent 63d82c0 commit 0a63b4e

File tree

5 files changed

+22
-86
lines changed

5 files changed

+22
-86
lines changed

lib/options/unitless-zero.js

-82
This file was deleted.

src/options/unitless-zero.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module.exports = {
2121

2222
if (value.is('dimension')) {
2323
var unit = value.first('ident').content;
24-
if (value.first('number').content[0] === '0' &&
24+
if (value.first('number').content === '0' &&
2525
UNITS.indexOf(unit) !== -1) {
2626
value.remove(1);
2727
}
2828
} else if (value.is('percentage')) {
2929
var number = value.first('number').content;
30-
if (number[0] === '0') {
30+
if (number === '0') {
3131
value.type = 'number';
3232
value.content = number;
3333
}
@@ -54,7 +54,7 @@ module.exports = {
5454
}
5555

5656
if (node.is('dimension') &&
57-
node.first('number').content[0] === '0' &&
57+
node.first('number').content === '0' &&
5858
node.first('ident').content !== 'deg') {
5959
detected.push(false);
6060
return;
@@ -63,7 +63,7 @@ module.exports = {
6363
// If we see a zero and previous node is not percentage
6464
// or dimension, then we have an option
6565
if (node.is('number') &&
66-
node.content[0] === '0' &&
66+
node.content === '0' &&
6767
!parent.is('percentage') &&
6868
!parent.is('dimension')) {
6969
detected.push(true);
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.example {
2+
bottom: 0em;
3+
left: 0.5em;
4+
right: 1em;
5+
top: 1.5em;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.example {
2+
bottom: 0;
3+
left: 0.5em;
4+
right: 1em;
5+
top: 1.5em;
6+
}

test/options/unitless-zero/test.js

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ describe('options/unitless-zero', function() {
3737
assert.equal(actual, 'div { -webkit-transform: rotate(0deg); }');
3838
});
3939
});
40+
41+
it('Issue 394', function() {
42+
this.comb.configure({ 'unitless-zero': true });
43+
this.shouldBeEqual('issue-394.css', 'issue-394.expected.css');
44+
});
4045
});
4146

4247
describe('detect', function() {
@@ -50,6 +55,7 @@ describe('options/unitless-zero', function() {
5055
);
5156
});
5257

58+
5359
it('Should detect zero with unit', function() {
5460
this.shouldDetect(
5561
['unitless-zero'],

0 commit comments

Comments
 (0)