Skip to content

Commit c9619dd

Browse files
committed
jshint config fix + codestyle
1 parent e51d1da commit c9619dd

File tree

4 files changed

+21
-37
lines changed

4 files changed

+21
-37
lines changed

.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: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = {
66
* @param {Boolean} isPrevDeclExists
77
*/
88
_splitBunch: function(bunch, isPrevDeclExists) {
9-
109
var nextBunch = [];
1110
var declAlready = false;
1211
var flag = false;
@@ -15,32 +14,31 @@ module.exports = {
1514

1615
for (var i = 0; i < bunch.length; ++i) {
1716
if (flag) { nextBunch.push(bunch[i]); continue; }
18-
if (bunch[i][0] == 'declaration') { declAlready = true; }
17+
if (bunch[i][0] === 'declaration') { declAlready = true; }
1918

2019
if (isPrevDeclExists && !declAlready) continue;
21-
if (bunch[i][0] != 's') continue;
20+
if (bunch[i][0] !== 's') continue;
2221

2322
var indexOfNewLine = bunch[i][1].indexOf('\n');
2423

25-
if (indexOfNewLine == -1) continue;
24+
if (indexOfNewLine === -1) continue;
2625

2726
nextBunch.push(['s', bunch[i][1].substr(indexOfNewLine + 1)]);
2827
bunch[i][1] = bunch[i][1].substr(0, indexOfNewLine + 1);
2928

3029
flag = i + 1;
3130
}
3231

33-
if (nextBunch.length == 1 && nextBunch[0][0] == 's') {
32+
if (nextBunch.length === 1 && nextBunch[0][0] === 's') {
3433
item = nextBunch[0];
35-
indexOf = item[1].lastIndexOf('\n')
34+
indexOf = item[1].lastIndexOf('\n');
3635

37-
indexOf != -1 && (item[1] = item[1].substr(indexOf + 1));
36+
indexOf !== -1 && (item[1] = item[1].substr(indexOf + 1));
3837
}
3938

4039
flag && bunch.splice(flag);
4140

4241
return nextBunch;
43-
4442
},
4543

4644
/**
@@ -52,31 +50,26 @@ module.exports = {
5250
* @param {node} node
5351
*/
5452
_createNodeExt: function(node) {
55-
5653
var extNode = [];
5754
var bunch = [];
5855
var nextBunch;
5956
var prevDeclPropertyName;
6057

6158
node.forEach(function(node) {
62-
63-
if (node[0] == 'declaration') {
59+
if (node[0] === 'declaration') {
6460
nextBunch = this._splitBunch(bunch, prevDeclPropertyName);
6561
extNode.push({ data: bunch, decl: prevDeclPropertyName });
6662
bunch = nextBunch;
6763
prevDeclPropertyName = node[1][1][1];
6864
}
69-
7065
bunch.push(node);
71-
7266
}, this);
7367

7468
nextBunch = this._splitBunch(bunch, prevDeclPropertyName);
7569
extNode.push({ data: bunch, decl: prevDeclPropertyName });
7670
nextBunch.length && extNode.push({ data: nextBunch });
7771

7872
return extNode;
79-
8073
},
8174

8275
/**
@@ -85,16 +78,13 @@ module.exports = {
8578
* @param {extNode} extNode
8679
*/
8780
_addGroupDelimiter: function(extNodePrev, extNode) {
88-
8981
if (!extNodePrev.decl || !extNode.decl) return;
9082

9183
var indexA = this._order[extNodePrev.decl];
9284
var indexB = this._order[extNode.decl];
93-
var isGroupBorder = indexA && indexB && indexA.group != indexB.group;
94-
95-
if (isGroupBorder)
96-
extNode.data.unshift(['s', '\n']);
85+
var isGroupBorder = indexA && indexB && indexA.group !== indexB.group;
9786

87+
if (isGroupBorder) extNode.data.unshift(['s', '\n']);
9888
},
9989

10090
/**
@@ -103,14 +93,11 @@ module.exports = {
10393
* @param {extNode} extNode
10494
*/
10595
_applyNodeExt: function(node, extNode) {
106-
10796
node.splice(0, node.length);
108-
10997
extNode.forEach(function(item, i) {
11098
i > 0 && this._addGroupDelimiter(extNode[i - 1], item);
11199
node.push.apply(node, item.data);
112100
}, this);
113-
114101
},
115102

116103
/**
@@ -120,18 +107,16 @@ module.exports = {
120107
* @returns {Object}
121108
*/
122109
setValue: function(value) {
123-
124110
if (!value) return;
125111

126-
this._order = {}
127-
value.forEach(function(group, groupIndex){
112+
this._order = {};
113+
value.forEach(function(group, groupIndex) {
128114
group.forEach(function(prop, propIndex) {
129115
this._order[prop] = { group: groupIndex, prop: propIndex };
130-
}, this)
116+
}, this);
131117
}, this);
132118

133119
return this;
134-
135120
},
136121

137122
/**
@@ -140,7 +125,6 @@ module.exports = {
140125
* @param {node} node
141126
*/
142127
process: function(nodeType, node) {
143-
144128
if (nodeType !== 'block') return;
145129

146130
var order = this._order;
@@ -149,21 +133,18 @@ module.exports = {
149133
var lastSymbols = nodeExt[nodeExt.length - 1].decl || nodeExt.pop();
150134

151135
nodeExt.sort(function(a, b) {
152-
153136
var indexA = order[a.decl] || { prop: -1 };
154137
var indexB = order[b.decl] || { prop: -1 };
155138
var groupDelta = indexA.group - indexB.group;
156139
var propDelta = indexA.prop - indexB.prop;
157140

158141
return groupDelta !== 0 ? groupDelta : propDelta;
159-
160142
});
161143

162144
firstSymbols && nodeExt.unshift(firstSymbols);
163145
lastSymbols && nodeExt.push(lastSymbols);
164146

165147
this._applyNodeExt(node, nodeExt);
166-
167148
}
168149

169150
};

0 commit comments

Comments
 (0)