Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .csscomb.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"block-indent": true,
"stick-brace": "\n",
"strip-spaces": true,
"unitless-zero": true,
"always-semicolon": true,
"sort-order": [
[
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Example configuration:
"block-indent": true,
"stick-brace": true,
"strip-spaces": true,
"unitless-zero": true,
"always-semicolon": true
}
```
Expand Down
1 change: 1 addition & 0 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Comb = function() {
'colon-space',
'rule-indent',
'block-indent',
'unitless-zero',
'sort-order'
];
this._config = {};
Expand Down
34 changes: 34 additions & 0 deletions lib/options/unitless-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {

/**
* Sets handler value.
*
* @param {Boolean} value Option value
* @returns {Object}
*/
setValue: function(value) {
if (value === true) {
this._value = value;
return this;
}
},

/**
* Processes tree node.
* @param {String} nodeType
* @param {node} node
*/
process: function(nodeType, node) {
if (nodeType === 'value' || nodeType === 'braces') {
node.forEach(function(child, index) {
if (
(child[0] === 'percentage' ||
child[0] === 'dimension' && ['cm', 'em', 'ex', 'pt', 'px'].indexOf(child[2][1]) !== -1) &&
child[1][1] === '0') {
node[index] = child[1];
}
});
}
}

};
4 changes: 2 additions & 2 deletions test/integral.expect.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* foobar */
@media all and (min-width:0px)
@media all and (min-width:0)
{
/* :before — бордер */
.radio-button_theme_normal .radio-button__radio:before
Expand Down Expand Up @@ -50,7 +50,7 @@ div p em
border-bottom: 1px solid red;
}

@media all and (min-width:0px)
@media all and (min-width:0)
{
/* В нажатом состоянии смещается вниз на 1px вся кнопка, текст не смещается */
.button_pressed_yes.button_shadow_yes
Expand Down
4 changes: 2 additions & 2 deletions test/integral.origin.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
/* _focused_yes */
.radio-button_theme_normal .radio-button__radio_focused_yes:before
{
-moz-box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0 1px 0 rgba(0,0,0,.07);
box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0 1px 0 rgba(0,0,0,.07);
-moz-box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0px 1px 0px rgba(0,0,0,.07);
box-shadow: 0 0 6px 2px rgba(255,204,0,.7), 0px 1px 0px rgba(0,0,0,.07);
}

}
Expand Down
45 changes: 45 additions & 0 deletions test/unitless-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var Comb = require('../lib/csscomb');
var assert = require('assert');

describe('options/unitless-zero', function() {
var comb;

beforeEach(function() {
comb = new Comb();
});

it('Should remove units in zero-valued dimensions', function() {
comb.configure({ 'unitless-zero': true });
assert.equal(
comb.processString(
'div { margin: 0em; padding: 0px }'
),
'div { margin: 0; padding: 0 }'
);
assert.equal(
comb.processString(
'div { margin: 0% }'
),
'div { margin: 0 }'
);
});

it('Should remove units in zero-valued media-query params', function() {
comb.configure({ 'unitless-zero': true });
assert.equal(
comb.processString('@media all and (min-width: 0px) { div { margin: 0em; padding: 0px } }'),
'@media all and (min-width: 0) { div { margin: 0; padding: 0 } }'
);
});

it('Should not remove units (degs) in rotate property', function() {
comb.configure({ 'unitless-zero': true });
assert.equal(
comb.processString(
'div { -webkit-transform: rotate(0deg); }'
),
'div { -webkit-transform: rotate(0deg); }'
);
});

});