Skip to content

Commit 6db3098

Browse files
committed
v0.0.9
2 parents 712566f + df07622 commit 6db3098

File tree

9 files changed

+346
-33
lines changed

9 files changed

+346
-33
lines changed

.csscomb.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
"counter-increment",
9191
"resize",
9292
"cursor",
93+
"-webkit-user-select",
94+
"-moz-user-select",
95+
"-ms-user-select",
96+
"user-select",
9397
"nav-index",
9498
"nav-up",
9599
"nav-right",
@@ -165,10 +169,6 @@
165169
"-ms-animation-iteration-count",
166170
"-o-animation-iteration-count",
167171
"animation-iteration-count",
168-
"-webkit-animation-iteration-count",
169-
"-moz-animation-iteration-count",
170-
"-ms-animation-iteration-count",
171-
"-o-animation-iteration-count",
172172
"animation-iteration-count",
173173
"-webkit-animation-direction",
174174
"-moz-animation-direction",
@@ -307,15 +307,6 @@
307307
"-webkit-box-shadow",
308308
"-moz-box-shadow",
309309
"box-shadow",
310-
"-webkit-box-shadow",
311-
"-moz-box-shadow",
312-
"box-shadow",
313-
"-webkit-box-shadow",
314-
"-moz-box-shadow",
315-
"box-shadow",
316-
"-webkit-box-shadow",
317-
"-moz-box-shadow",
318-
"box-shadow",
319310
"filter:progid:DXImageTransform.Microsoft.gradient",
320311
"-ms-filter:\\'progid:DXImageTransform.Microsoft.gradient",
321312
"text-shadow"

.jscs.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"return",
1818
"catch"
1919
],
20+
"requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
21+
"disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true },
2022
"disallowMultipleVarDecl": true,
2123
"disallowLeftStickedOperators": [
2224
"?",
@@ -60,14 +62,15 @@
6062
"string"
6163
],
6264
"disallowKeywords": ["with"],
63-
"disallowMulipleLineBreaks": true,
6465
"disallowKeywordsOnNewLine": ["else", "catch"],
6566
"requireLineFeedAtFileEnd": true,
6667
"validateJSDoc": {
6768
"checkParamNames": true,
69+
"checkRedundantParams": true,
6870
"requireParamTypes": true
6971
},
7072
"requireSpacesInsideObjectBrackets": "all",
7173
"disallowSpacesInsideArrayBrackets": true,
72-
"disallowSpaceAfterObjectKeys": true
74+
"disallowSpaceAfterObjectKeys": true,
75+
"disallowQuotedKeysInObjects": true
7376
}

.jshint-groups.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
groups: {
2323
js: {
2424
options: { node: true },
25-
includes: ['lib/*.js']
25+
includes: ['lib/**/*.js']
2626
},
2727
test: {
2828
options: {

lib/options/block-indent.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ module.exports = {
2121
* @param {node} node
2222
*/
2323
process: function(nodeType, node, level) {
24+
var value;
25+
var space;
26+
2427
// Add right space before closing brace
2528
if (nodeType === 'atrulers' || nodeType === 'block') {
26-
var value = '\n' + new Array(level + 1).join(this._value);
29+
value = '\n' + new Array(level + 1).join(this._value);
2730
if (node[node.length - 1][0] === 's') node.pop();
2831
node.push(['s', value]);
2932
}
@@ -43,10 +46,10 @@ module.exports = {
4346
for (var i = 0; i < node.length; i++) {
4447
var nodeItem = node[i];
4548
if (nodeItem[0] === 'atruler' || nodeItem[0] === 'ruleset') {
46-
var value = (i < 2 && isFirst ? '' : '\n') + new Array(level + 1).join(this._value);
49+
value = (i < 2 && isFirst ? '' : '\n') + new Array(level + 1).join(this._value);
4750
isFirst = false;
4851

49-
var space = node[i - 1];
52+
space = node[i - 1];
5053
if (!space || space[0] !== 's') {
5154
space = ['s', ''];
5255
if (i) {
@@ -63,7 +66,7 @@ module.exports = {
6366

6467
// Add space before block opening brace
6568
if (nodeType === 'simpleselector') {
66-
var space = node[node.length - 1];
69+
space = node[node.length - 1];
6770
if (space[0] === 's' && space[1].match('\n')) {
6871
space[1] += new Array(level + 1).join(this._value);
6972
}

lib/options/rule-indent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
}
4242
space[1] = space[1].replace(/(\n)?([\t ]+)?$/, value);
4343
}
44-
};
44+
}
4545
}
4646
}
4747

lib/options/sort-order.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
module.exports = {
2+
3+
/**
4+
* Internal. Smart split bunch on '\n' symbols;
5+
* @param {Array} bunch
6+
* @param {Boolean} isPrevDeclExists
7+
*/
8+
_splitBunch: function(bunch, isPrevDeclExists) {
9+
var nextBunch = [];
10+
var declAlready = false;
11+
var flag = false;
12+
var item;
13+
var indexOf;
14+
15+
for (var i = 0; i < bunch.length; ++i) {
16+
if (flag) { nextBunch.push(bunch[i]); continue; }
17+
if (bunch[i][0] === 'declaration') { declAlready = true; }
18+
19+
if (isPrevDeclExists && !declAlready) continue;
20+
if (bunch[i][0] !== 's') continue;
21+
22+
var indexOfNewLine = bunch[i][1].indexOf('\n');
23+
24+
if (indexOfNewLine === -1) continue;
25+
26+
nextBunch.push(['s', bunch[i][1].substr(indexOfNewLine + 1)]);
27+
bunch[i][1] = bunch[i][1].substr(0, indexOfNewLine + 1);
28+
29+
flag = i + 1;
30+
}
31+
32+
if (nextBunch.length === 1 && nextBunch[0][0] === 's') {
33+
item = nextBunch[0];
34+
indexOf = item[1].lastIndexOf('\n');
35+
36+
indexOf !== -1 && (item[1] = item[1].substr(indexOf + 1));
37+
}
38+
39+
flag && bunch.splice(flag);
40+
41+
return nextBunch;
42+
},
43+
44+
/**
45+
* Internal. Create extended node in format of list
46+
* {
47+
* data:[,,declaration,]
48+
* decl: declarationPropertyName
49+
* };
50+
* @param {node} node
51+
*/
52+
_createNodeExt: function(node) {
53+
var extNode = [];
54+
var bunch = [];
55+
var nextBunch;
56+
var prevDeclPropertyName;
57+
58+
node.forEach(function(node) {
59+
if (node[0] === 'declaration') {
60+
nextBunch = this._splitBunch(bunch, prevDeclPropertyName);
61+
extNode.push({ data: bunch, decl: prevDeclPropertyName });
62+
bunch = nextBunch;
63+
prevDeclPropertyName = node[1][1][1];
64+
}
65+
bunch.push(node);
66+
}, this);
67+
68+
nextBunch = this._splitBunch(bunch, prevDeclPropertyName);
69+
extNode.push({ data: bunch, decl: prevDeclPropertyName });
70+
nextBunch.length && extNode.push({ data: nextBunch });
71+
72+
return extNode;
73+
},
74+
75+
/**
76+
* Internal. Add delimiter at the end of groups of properties
77+
* @param {extNode} extNodePrev
78+
* @param {extNode} extNode
79+
*/
80+
_addGroupDelimiter: function(extNodePrev, extNode) {
81+
if (!extNodePrev.decl || !extNode.decl) return;
82+
83+
var indexA = this._order[extNodePrev.decl];
84+
var indexB = this._order[extNode.decl];
85+
var isGroupBorder = indexA && indexB && indexA.group !== indexB.group;
86+
87+
if (isGroupBorder) extNode.data.unshift(['s', '\n']);
88+
},
89+
90+
/**
91+
* Internal. apply extNode back at common format node.
92+
* @param {node} node
93+
* @param {extNode} extNode
94+
*/
95+
_applyNodeExt: function(node, extNode) {
96+
node.splice(0, node.length);
97+
extNode.forEach(function(item, i) {
98+
i > 0 && this._addGroupDelimiter(extNode[i - 1], item);
99+
node.push.apply(node, item.data);
100+
}, this);
101+
},
102+
103+
/**
104+
* Sets handler value.
105+
*
106+
* @param {Array} value Option value
107+
* @returns {Object}
108+
*/
109+
setValue: function(value) {
110+
if (!value) return;
111+
112+
this._order = {};
113+
value.forEach(function(group, groupIndex) {
114+
group.forEach(function(prop, propIndex) {
115+
this._order[prop] = { group: groupIndex, prop: propIndex };
116+
}, this);
117+
}, this);
118+
119+
return this;
120+
},
121+
122+
/**
123+
* Processes tree node.
124+
* @param {String} nodeType
125+
* @param {node} node
126+
*/
127+
process: function(nodeType, node) {
128+
if (nodeType !== 'block') return;
129+
130+
var order = this._order;
131+
var nodeExt = this._createNodeExt(node);
132+
var firstSymbols = nodeExt[0].decl || nodeExt.shift();
133+
var lastSymbols = nodeExt[nodeExt.length - 1].decl || nodeExt.pop();
134+
135+
nodeExt.sort(function(a, b) {
136+
var indexA = order[a.decl] || { prop: -1 };
137+
var indexB = order[b.decl] || { prop: -1 };
138+
var groupDelta = indexA.group - indexB.group;
139+
var propDelta = indexA.prop - indexB.prop;
140+
141+
return groupDelta !== 0 ? groupDelta : propDelta;
142+
});
143+
144+
firstSymbols && nodeExt.unshift(firstSymbols);
145+
lastSymbols && nodeExt.push(lastSymbols);
146+
147+
this._applyNodeExt(node, nodeExt);
148+
}
149+
150+
};

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csscomb",
33
"description": "Tool for beautify CSS",
4-
"version": "0.0.8",
4+
"version": "0.0.9",
55
"homepage": "http://csscomb.com/",
66
"author": "Mikhail Troshev <mishanga@yandex-team.ru>",
77
"repository": "https://github.com/csscomb/csscomb.js",
@@ -17,6 +17,16 @@
1717
"web": "http://miripiruni.org/"
1818
}
1919
],
20+
"contributors": [
21+
{
22+
"name": "Sergey Puzankov",
23+
"email": "puzankov@yandex-team.ru"
24+
},
25+
{
26+
"name": "Denis Payase",
27+
"email": "lostsoul@yandex-team.ru"
28+
}
29+
],
2030
"engines": {
2131
"node": "0.8 | 0.10"
2232
},
@@ -30,7 +40,7 @@
3040
"devDependencies": {
3141
"jshint-groups": "0.5.1",
3242
"jshint": "2.1.7",
33-
"jscs": "1.0.2",
43+
"jscs": "1.0.5",
3444
"mocha": "1.11.0"
3545
},
3646
"main": "./lib/csscomb.js",

0 commit comments

Comments
 (0)