Skip to content

Commit cedef69

Browse files
committed
Added JSHint to master
1 parent 7756438 commit cedef69

File tree

5 files changed

+84
-43
lines changed

5 files changed

+84
-43
lines changed

.jshintrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"bitwise" : true,
3+
"camelcase" : true,
4+
"curly" : true,
5+
"eqeqeq" : true,
6+
"forin" : false,
7+
"immed" : true,
8+
"indent" : 2,
9+
"latedef" : true,
10+
"maxcomplexity": 30,
11+
"maxdepth" : false,
12+
"maxerr" : 10000,
13+
"maxparams" : false,
14+
"maxstatements": false,
15+
"maxlen" : false,
16+
"multistr" : true,
17+
"newcap" : true,
18+
"noarg" : true,
19+
"noempty" : false,
20+
"nonew" : false,
21+
"plusplus" : false,
22+
"quotmark" : true,
23+
"scripturl" : true,
24+
"strict" : true,
25+
"sub" : true,
26+
"supernew" : true,
27+
"trailing" : true,
28+
"undef" : true,
29+
"unused" : true,
30+
"node" : true
31+
}

src/file.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ exports = module.exports = {
114114
}
115115

116116
// SCSS file
117-
else if (utils.getExtension(path) === "scss") {
117+
else if (utils.getExtension(path) === 'scss') {
118118
promises.push(exports.file.process(path).then(function (response) {
119119
data = data.concat(response);
120120
}));
@@ -212,8 +212,14 @@ exports = module.exports = {
212212
exports.postTreatData(data);
213213

214214
return exports.splitData(data.data.sort(function (a, b) {
215-
if (a.name > b.name) return 1;
216-
if (a.name < b.name) return -1;
215+
if (a.name > b.name) {
216+
return 1;
217+
}
218+
219+
if (a.name < b.name) {
220+
return -1;
221+
}
222+
217223
return 0;
218224
}));
219225
});
@@ -264,7 +270,7 @@ exports = module.exports = {
264270

265271
// Incorrect @alias
266272
else {
267-
logger.log("Item `" + name + " is an alias of `" + item.alias + "` but this item doesn't exist.");
273+
logger.log('Item `' + name + ' is an alias of `' + item.alias + '` but this item doesn\'t exist.');
268274
}
269275
}
270276
},
@@ -301,7 +307,7 @@ exports = module.exports = {
301307

302308
// Incorrect @requires
303309
else {
304-
logger.log("Item `" + name + " requires `" + item.requires[i].item + "` but this item doesn't exist.");
310+
logger.log('Item `' + name + ' requires `' + item.requires[i].item + '` but this item doesn\'t exist.');
305311
}
306312
}
307313
}
@@ -313,7 +319,7 @@ exports = module.exports = {
313319
*/
314320
raiseWarnings: function (data) {
315321
var name, item, i;
316-
var validTypes = ["*", "arglist", "bool", "color", "list", "map", "null", "number", "string"];
322+
var validTypes = ['*', 'arglist', 'bool', 'color', 'list', 'map', 'null', 'number', 'string'];
317323

318324
if (logger.enabled === false) {
319325
return;
@@ -326,7 +332,7 @@ exports = module.exports = {
326332
if (utils.isset(item.parameters)) {
327333
for (i = 0; i < item.parameters.length; i++) {
328334
if (validTypes.indexOf(item.parameters[i].type.toLowerCase()) === -1) {
329-
logger.log("Parameter `" + item.parameters[i].name + "` from item `" + item.name + "` is from type `" + item.parameters[i].type + "` which is not a valid Sass type.");
335+
logger.log('Parameter `' + item.parameters[i].name + '` from item `' + item.name + '` is from type `' + item.parameters[i].type + '` which is not a valid Sass type.');
330336
}
331337
}
332338
}
@@ -335,7 +341,7 @@ exports = module.exports = {
335341
if (utils.isset(item.returns) && item.returns.type) {
336342
for (i = 0; i < item.returns.type.length; i++) {
337343
if (validTypes.indexOf(item.returns.type[i].trim().toLowerCase()) === -1) {
338-
logger.log("Item `" + item.name + "` can return a `" + item.returns.type[i] + "` which is not a valid Sass type.");
344+
logger.log('Item `' + item.name + '` can return a `' + item.returns.type[i] + '` which is not a valid Sass type.');
339345
}
340346
}
341347
}
@@ -344,7 +350,7 @@ exports = module.exports = {
344350
if (utils.isset(item.links)) {
345351
for (i = 0; i < item.links.length; i++) {
346352
if (!item.links[i].url.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)) {
347-
logger.log("Item `" + item.name + "` has a link leading to an invalid URL (`" + item.links[i].url + "`).");
353+
logger.log('Item `' + item.name + '` has a link leading to an invalid URL (`' + item.links[i].url + '`).');
348354
}
349355
}
350356
}

src/parser.js

+31-27
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ exports = module.exports = {
2020
while (previousLine >= 0) {
2121
// If it's an empty line, break (unless it hasn't started yet)
2222
if (regex.isEmpty(array[previousLine]) !== null) {
23-
if (comments.length > 0) break;
23+
if (comments.length > 0) {
24+
break;
25+
}
2426
}
2527

2628
// If it's not a comment, break
@@ -46,7 +48,7 @@ exports = module.exports = {
4648
* @return {Object} function/mixin documentation
4749
*/
4850
parseCommentBlock: function (comments) {
49-
var line, doc = {
51+
var _line, doc = {
5052
'parameters': [],
5153
'throws': [],
5254
'todos': [],
@@ -65,34 +67,34 @@ exports = module.exports = {
6567
}
6668
};
6769

68-
comments.forEach(function (line, index) {
69-
line = exports.parseLine(utils.uncomment(line));
70+
comments.forEach(function (line) {
71+
_line = exports.parseLine(utils.uncomment(line));
7072

7173
// Separator or @ignore
72-
if (!line) {
74+
if (!_line) {
7375
return false;
7476
}
7577

7678
// Array things (@throws, @parameters...)
77-
if (line.array === true) {
78-
doc[line.type].push(line.value);
79+
if (_line.array === true) {
80+
doc[_line.type].push(_line.value);
7981
}
8082

81-
else if (line.type === 'description') {
83+
else if (_line.type === 'description') {
8284
if (doc.description.length === 0) {
83-
doc.description = line.value;
85+
doc.description = _line.value;
8486
}
8587

8688
else {
87-
doc.description += line.value;
89+
doc.description += _line.value;
8890
}
8991

9092
doc.description += '\n';
9193
}
9294

9395
// Anything else
9496
else {
95-
doc[line.type] = line.value;
97+
doc[_line.type] = _line.value;
9698
}
9799

98100
});
@@ -106,16 +108,16 @@ exports = module.exports = {
106108
* @return {Object} function/mixin documentation
107109
*/
108110
parseVariableBlock: function (comments) {
109-
var line, doc = {
111+
var _line, doc = {
110112
'description': '',
111113
'datatype': ''
112114
};
113115

114-
comments.forEach(function (line, index) {
115-
line = regex.isVar(utils.uncomment(line));
116+
comments.forEach(function (line) {
117+
_line = regex.isVar(utils.uncomment(line));
116118

117-
doc.datatype = line[1];
118-
doc.description = line[2];
119+
doc.datatype = _line[1];
120+
doc.description = _line[2];
119121
});
120122

121123
return doc;
@@ -127,16 +129,16 @@ exports = module.exports = {
127129
* @return {Array} array of documented functions/mixins
128130
*/
129131
parseFile: function (content) {
130-
var array = content.split("\n"),
131-
tree = [];
132+
var array = content.split('\n'),
133+
tree = [], item;
132134

133135
// Looping through the file
134136
array.forEach(function (line, index) {
135137
var isCallable = regex.isFunctionOrMixin(line);
136138

137139
// If it's either a mixin or a function
138140
if (isCallable) {
139-
var item = exports.parseCommentBlock(exports.findCommentBlock(index, array));
141+
item = exports.parseCommentBlock(exports.findCommentBlock(index, array));
140142
item.type = isCallable[1];
141143
item.name = isCallable[2];
142144

@@ -147,11 +149,11 @@ exports = module.exports = {
147149
var isVariable = regex.isVariable(line);
148150

149151
if (isVariable) {
150-
var item = exports.parseVariableBlock(exports.findCommentBlock(index, array));
151-
item.type = "variable";
152+
item = exports.parseVariableBlock(exports.findCommentBlock(index, array));
153+
item.type = 'variable';
152154
item.name = isVariable[1];
153155
item.value = isVariable[2];
154-
item.access = isVariable[3] == "!global" ? "public" : "private";
156+
item.access = isVariable[3] === '!global' ? 'public' : 'private';
155157

156158
tree.push(item);
157159
}
@@ -172,13 +174,11 @@ exports = module.exports = {
172174
tokens = ['returns', 'parameters', 'deprecated', 'author', 'access', 'throws', 'todo', 'alias', 'link', 'requires', 'since'];
173175

174176
// Useless line, skip
175-
if (line.length === 0
176-
|| regex.isSeparator(line)
177-
|| regex.isIgnore(line)) {
177+
if (line.length === 0 || regex.isSeparator(line) || regex.isIgnore(line)) {
178178
return false;
179179
}
180180

181-
for (var i = 0; i < tokens.length; i++) {
181+
for (i = 0; i < tokens.length; i++) {
182182
value = regex['is' + tokens[i].capitalize()](line);
183183

184184
if (value !== null) {
@@ -222,10 +222,14 @@ exports = module.exports = {
222222
break;
223223

224224
case 'link':
225-
res.value = { 'url': value[1], 'caption': value[2] }
225+
res.value = { 'url': value[1], 'caption': value[2] };
226226
break;
227227

228228
case 'description':
229+
res.value = line;
230+
res.type = 'description';
231+
break;
232+
229233
default:
230234
res.value = line;
231235
res.type = 'description';

src/regex.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
var types = "(?:null|\\*|number|color|string|list|map|bool|arglist|spritemap)";
4-
var multipleTypes = "\\{\\s*(" + types + "(?:\\s*\\|\\s*" + types + ")*)\\s*\\}";
3+
var types = '(?:null|\\*|number|color|string|list|map|bool|arglist|spritemap)';
4+
var multipleTypes = '\\{\\s*(' + types + '(?:\\s*\\|\\s*' + types + ')*)\\s*\\}';
55

66
exports = module.exports = {
77

@@ -20,7 +20,7 @@ exports = module.exports = {
2020
* @return {Boolean}
2121
*/
2222
isParameters: function (line) {
23-
var re = new RegExp("^@(?:param|arg|argument)\\s+" + multipleTypes + "\\s+\\$([\\w-]+)(?:\\s+\\((.+)\\))?(?:\\s+-?\\s*(.+))?", "i");
23+
var re = new RegExp('^@(?:param|arg|argument)\\s+' + multipleTypes + '\\s+\\$([\\w-]+)(?:\\s+\\((.+)\\))?(?:\\s+-?\\s*(.+))?', 'i');
2424
return line.match(re);
2525
},
2626

@@ -30,7 +30,7 @@ exports = module.exports = {
3030
* @return {Boolean}
3131
*/
3232
isReturns: function (line) {
33-
var re = new RegExp("^@returns?(?:\\s+" + multipleTypes + ")(?:\\s+(.+))?", "i");
33+
var re = new RegExp('^@returns?(?:\\s+' + multipleTypes + ')(?:\\s+(.+))?', 'i');
3434
return line.match(re);
3535
},
3636

@@ -40,7 +40,7 @@ exports = module.exports = {
4040
* @return {Boolean}
4141
*/
4242
isVar: function (line) {
43-
var re = new RegExp("^@var(?:\\s+" + multipleTypes + ")(?:\\s+-?\\s*(.+))?", "i");
43+
var re = new RegExp('^@var(?:\\s+' + multipleTypes + ')(?:\\s+-?\\s*(.+))?', 'i');
4444
return line.match(re);
4545
},
4646

src/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports = module.exports = {
5353
* @return {Bool}
5454
*/
5555
isset: function (value) {
56-
return typeof value !== "undefined";
56+
return typeof value !== 'undefined';
5757
}
5858

5959
};
@@ -80,4 +80,4 @@ String.prototype.trim = function () {
8080
*/
8181
String.prototype.capitalize = function () {
8282
return this.charAt(0).toUpperCase() + this.slice(1);
83-
}
83+
};

0 commit comments

Comments
 (0)