Skip to content

Commit 8f3e458

Browse files
author
Igor Novak
committed
Added unitless zero option
1 parent 8ba74ea commit 8f3e458

File tree

7 files changed

+86
-4
lines changed

7 files changed

+86
-4
lines changed

.csscomb.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"block-indent": true,
1010
"stick-brace": "\n",
1111
"strip-spaces": true,
12+
"unitless-zero": true,
1213
"always-semicolon": true,
1314
"sort-order": [
1415
[

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Example configuration:
4040
"block-indent": true,
4141
"stick-brace": true,
4242
"strip-spaces": true,
43+
"unitless-zero": true,
4344
"always-semicolon": true
4445
}
4546
```

lib/csscomb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Comb = function() {
1818
'colon-space',
1919
'rule-indent',
2020
'block-indent',
21+
'unitless-zero',
2122
'sort-order'
2223
];
2324
this._config = {};

lib/options/unitless-zero.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
3+
/**
4+
* Sets handler value.
5+
*
6+
* @param {Boolean} value Option value
7+
* @returns {Object}
8+
*/
9+
setValue: function(value) {
10+
if (value === true) {
11+
this._value = value;
12+
return this;
13+
}
14+
},
15+
16+
/**
17+
* Processes tree node.
18+
* @param {String} nodeType
19+
* @param {node} node
20+
*/
21+
process: function(nodeType, node) {
22+
if (nodeType === 'value' || nodeType === 'braces') {
23+
node.forEach(function(child, index) {
24+
if (
25+
(child[0] === 'percentage' ||
26+
child[0] === 'dimension' && ['cm', 'em', 'ex', 'pt', 'px'].indexOf(child[2][1]) !== -1) &&
27+
child[1][1] === '0') {
28+
node[index] = child[1];
29+
}
30+
});
31+
}
32+
}
33+
34+
};

test/integral.expect.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* foobar */
2-
@media all and (min-width:0px)
2+
@media all and (min-width:0)
33
{
44
/* :before — бордер */
55
.radio-button_theme_normal .radio-button__radio:before
@@ -50,7 +50,7 @@ div p em
5050
border-bottom: 1px solid red;
5151
}
5252

53-
@media all and (min-width:0px)
53+
@media all and (min-width:0)
5454
{
5555
/* В нажатом состоянии смещается вниз на 1px вся кнопка, текст не смещается */
5656
.button_pressed_yes.button_shadow_yes

test/integral.origin.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
/* _focused_yes */
2727
.radio-button_theme_normal .radio-button__radio_focused_yes:before
2828
{
29-
-moz-box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0 1px 0 rgba(0,0,0,.07);
30-
box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0 1px 0 rgba(0,0,0,.07);
29+
-moz-box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0px 1px 0px rgba(0,0,0,.07);
30+
box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0px 1px 0px rgba(0,0,0,.07);
3131
}
3232

3333
}

test/unitless-zero.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/unitless-zero', function() {
5+
var comb;
6+
7+
beforeEach(function() {
8+
comb = new Comb();
9+
});
10+
11+
it('Should remove units in zero-valued dimensions', function() {
12+
comb.configure({ 'unitless-zero': true });
13+
assert.equal(
14+
comb.processString(
15+
'div { margin: 0em; padding: 0px }'
16+
),
17+
'div { margin: 0; padding: 0 }'
18+
);
19+
assert.equal(
20+
comb.processString(
21+
'div { margin: 0% }'
22+
),
23+
'div { margin: 0 }'
24+
);
25+
});
26+
27+
it('Should remove units in zero-valued media-query params', function() {
28+
comb.configure({ 'unitless-zero': true });
29+
assert.equal(
30+
comb.processString('@media all and (min-width: 0px) { div { margin: 0em; padding: 0px } }'),
31+
'@media all and (min-width: 0) { div { margin: 0; padding: 0 } }'
32+
);
33+
});
34+
35+
it('Should not remove units (degs) in rotate property', function() {
36+
comb.configure({ 'unitless-zero': true });
37+
assert.equal(
38+
comb.processString(
39+
'div { -webkit-transform: rotate(0deg); }'
40+
),
41+
'div { -webkit-transform: rotate(0deg); }'
42+
);
43+
});
44+
45+
});

0 commit comments

Comments
 (0)