Skip to content

Commit b39639b

Browse files
authored
Merge pull request #85 from montagejs/bugs/jshint
jshint
2 parents bdc9446 + d10561a commit b39639b

28 files changed

+118
-86
lines changed

.jshintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/**
2+
node_modules/**
3+
templates/**/**__name__*.js
4+
templates/**/__name__/**/*.js

.jshintrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"node": true,
3+
"bitwise": true,
4+
"camelcase": true,
5+
"curly": true,
6+
"eqeqeq": true,
7+
"forin": true,
8+
"noarg": true,
9+
"noempty": true,
10+
"nonew": true,
11+
"undef": true,
12+
"unused": false,
13+
"trailing": true,
14+
"indent": 4,
15+
"boss": true,
16+
"eqnull": true,
17+
"browser": true,
18+
"globals": {
19+
"require": false,
20+
"exports": false,
21+
"module": false,
22+
"global": false
23+
}
24+
}

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_js:
55
- 8
66
script: npm run $COMMAND
77
env:
8+
- COMMAND=lint
89
- COMMAND=test
910
notifications:
1011
irc:

cli.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929
POSSIBILITY OF SUCH DAMAGE.
3030
</copyright> */
3131

32-
var fs = require("fs");
33-
var path = require("path");
34-
3532
var Command = require("commander").Command;
3633

3734
var config = require("./package.json");

lib/create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var fs = require("fs");
3333
var path = require("path");
3434
var MinitError = require("./error").MinitError;
3535

36-
var create = exports = module.exports = function(templateName, config, templateModule) {
36+
var create = module.exports = function(templateName, config, templateModule) {
3737

3838
config.templateName = templateName;
3939

@@ -70,7 +70,7 @@ var create = exports = module.exports = function(templateName, config, templateM
7070
};
7171
exports.create = create;
7272

73-
exports.addCommandsTo = function(program) {
73+
exports.addCommandsTo = create.addCommandsTo = function(program) {
7474
var templatesDir = path.join(program.minitHome, "templates");
7575
var fileNames = fs.readdirSync(templatesDir);
7676
fileNames.forEach(function(filename) {

lib/mustache.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
1414
exports.render = render;
1515
exports.clearCache = clearCache;
1616

17-
// This is here for backwards compatibility with 0.4.x.
18-
exports.to_html = function (template, view, partials, send) {
17+
// This is here for backwards compatibility with 0.4.x.
18+
exports.to_html = function (template, view, partials, send) { // jshint ignore:line
1919
var result = render(template, view, partials);
2020

2121
if (typeof send === "function") {
@@ -61,7 +61,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
6161
var trim;
6262
if (_trim) {
6363
trim = function (string) {
64-
return string == null ? "" : _trim.call(string);
64+
return string === null || string === undefined ? "" : _trim.call(string);
6565
};
6666
} else {
6767
var trimLeft, trimRight;
@@ -76,7 +76,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
7676
}
7777

7878
trim = function (string) {
79-
return string == null ? "" :
79+
return string === null || string === undefined ? "" :
8080
String(string).replace(trimLeft, "").replace(trimRight, "");
8181
};
8282
}
@@ -142,7 +142,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
142142
while (j < lastIndex) {
143143
context = context[names[j++]];
144144

145-
if (context == null) {
145+
if (context === null || context === undefined) {
146146
break;
147147
}
148148

@@ -160,7 +160,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
160160
value = value.call(localStack[localStack.length - 1]);
161161
}
162162

163-
if (value == null) {
163+
if (value === null || value === undefined) {
164164
return defaultValue;
165165
}
166166

@@ -175,7 +175,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
175175
// From the spec: inverted sections may render text once based on the
176176
// inverse value of the key. That is, they will be rendered if the key
177177
// doesn't exist, is false, or is an empty list.
178-
if (value == null || value === false || (isArray(value) && value.length === 0)) {
178+
if (value === null || value === undefined || value === false || (isArray(value) && value.length === 0)) {
179179
buffer += callback();
180180
}
181181
} else if (isArray(value)) {
@@ -294,9 +294,9 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
294294

295295
var closeSection = function (source) {
296296
var name = trim(source);
297-
var openName = sectionStack.length != 0 && sectionStack[sectionStack.length - 1].name;
297+
var openName = sectionStack.length !== 0 && sectionStack[sectionStack.length - 1].name;
298298

299-
if (!openName || name != openName) {
299+
if (!openName || name !== openName) {
300300
throw debug(new Error('Section named "' + name + '" was never opened'), template, line, options.file);
301301
}
302302

@@ -373,7 +373,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
373373
callback = closeSection;
374374
break;
375375
case "{": // plain variable
376-
closeTag = "}" + closeTag;
376+
closeTag = "}" + closeTag; // jshint ignore:line
377377
// fall through
378378
case "&": // plain variable
379379
i++;
@@ -399,7 +399,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
399399

400400
// Maintain line count for \n in source.
401401
var n = 0;
402-
while (~(n = source.indexOf("\n", n))) {
402+
while (~(n = source.indexOf("\n", n))) { // jshint ignore:line
403403
line++;
404404
n++;
405405
}
@@ -437,7 +437,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
437437
}
438438
}
439439

440-
if (sectionStack.length != 0) {
440+
if (sectionStack.length !== 0) {
441441
throw debug(new Error('Section "' + sectionStack[sectionStack.length - 1].name + '" was not closed properly'), template, line, options.file);
442442
}
443443

@@ -455,7 +455,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
455455
var body = code.join("").replace(/buffer \+= "";\n/g, "");
456456

457457
if (options.debug) {
458-
if (typeof console != "undefined" && console.log) {
458+
if (typeof console !== "undefined" && console.log) {
459459
console.log(body);
460460
} else if (typeof print === "function") {
461461
print(body);
@@ -471,7 +471,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
471471
function _compile(template, options) {
472472
var args = "view,partials,stack,lookup,escapeHTML,renderSection,render";
473473
var body = parse(template, options);
474-
var fn = new Function(args, body);
474+
var fn = new Function(args, body); // jshint ignore:line
475475

476476
// This anonymous function wraps the generated function so we can do
477477
// argument coercion, setup some variables, and handle any errors

lib/template-base.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
6565

6666
validatePackageHome: {
6767
value: function (value) {
68-
return new String(value)
68+
return String(value);
6969
}
7070
},
7171

@@ -74,7 +74,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
7474
var packageHome = process.cwd(),
7575
root = qfs.root();
7676
if (root === "") {
77-
root = "/"
77+
root = "/";
7878
}
7979
while (true) {
8080
if (FS.existsSync(Path.join(packageHome, "package.json"))) {
@@ -86,7 +86,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
8686
break;
8787
}
8888
}
89-
return packageHome
89+
return packageHome;
9090
}
9191
},
9292

@@ -119,13 +119,13 @@ exports.TemplateBase = Object.create(Object.prototype, {
119119
if (exists) {
120120
promise = qfs.removeTree(mainBuildDir)
121121
.then(function() {
122-
return qfs.makeDirectory(mainBuildDir)
122+
return qfs.makeDirectory(mainBuildDir);
123123
});
124124
} else {
125125
promise = qfs.makeDirectory(mainBuildDir);
126126
}
127127
return promise.then(function() {
128-
return qfs.copyTree(self.directory, self.buildDir)
128+
return qfs.copyTree(self.directory, self.buildDir);
129129
})
130130
.then(function() {
131131
return self.processBuildDirectory(self.buildDir);
@@ -136,7 +136,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
136136

137137
finalDestination: {
138138
get: function() {
139-
return Path.join(this.options.packageHome || "", this.options.destination || "")
139+
return Path.join(this.options.packageHome || "", this.options.destination || "");
140140
}
141141
},
142142

@@ -160,7 +160,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
160160
}
161161
});
162162
}));
163-
})
163+
});
164164
});
165165
}
166166
},
@@ -169,7 +169,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
169169
value: function() {
170170
var self = this;
171171
return this.finish(this.finalDestination).then(function() {
172-
return qfs.removeDirectory(self.buildDir)
172+
return qfs.removeDirectory(self.buildDir);
173173
});
174174
}
175175
},
@@ -216,7 +216,7 @@ exports.TemplateBase = Object.create(Object.prototype, {
216216
var newContents = self.applyTransform(data, self.options);
217217

218218
return qfs.write(filename, newContents).then(function () {
219-
return self.rename(filename)
219+
return self.rename(filename);
220220
}).fail(function () {
221221
console.log("Error writing to " + filename + ".");
222222
throw "Error writing to " + filename + ".";
@@ -233,12 +233,15 @@ exports.TemplateBase = Object.create(Object.prototype, {
233233

234234
rename: {
235235
value: function(filename) {
236-
var newName = filename;
237-
for (var name in this.options) {
238-
newName = newName.replace(
239-
FILENAME_VARIABLE_START + name + FILENAME_VARIABLE_END,
240-
this.options[name]
241-
);
236+
var newName = filename,
237+
options = this.options;
238+
for (var name in options) {
239+
if (options.hasOwnProperty(name)) {
240+
newName = newName.replace(
241+
FILENAME_VARIABLE_START + name + FILENAME_VARIABLE_END,
242+
options[name]
243+
);
244+
}
242245
}
243246
if(newName === filename) {
244247
return Q.resolve(filename);

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
},
2424
"devDependencies": {
2525
"jasmine-node": "^1.14.5",
26+
"jshint": "^2.9.5",
2627
"mocks": "0.0.15",
2728
"sandboxed-module": "^0.3.0"
2829
},
2930
"engines": {
30-
"node": "~0.10.2"
31+
"node": "=>4.8.4",
32+
"npm": "=>2.15.11"
3133
},
3234
"bin": {
3335
"minit": "minit"
3436
},
3537
"scripts": {
36-
"test": "node run-test.js"
38+
"test": "node run-test.js",
39+
"lint": "jshint ."
3740
},
3841
"preferGlobal": true
3942
}

run-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ jasmine.Block.prototype.execute = function (onComplete) {
5555

5656
jasmine.executeSpecsInFolder({
5757
"specFolders": [__dirname+ "/test"],
58-
"onComplete": function(runner, log){
59-
if (runner.results().failedCount == 0) {
58+
"onComplete": function(runner/*, log*/){
59+
if (runner.results().failedCount === 0) {
6060
process.exit(0);
6161
}
6262
else {

templates/app.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
var PackageTemplate = require("./package").Template;
22
var ArgumentError = require("../lib/error.js").ArgumentError;
3-
var path = require('path');
43
var fs = require('fs');
5-
var npm = require("npm");
6-
var Q = require('q');
74
var removeDiacritics = require("diacritics").remove;
85

96
var _fromCamelToDashes = function(name) {
@@ -62,7 +59,7 @@ exports.Template = Object.create(PackageTemplate, {
6259
},
6360

6461
defaultPackageHome: {
65-
value: function (value) {
62+
value: function () {
6663
return process.cwd();
6764
}
6865
}

0 commit comments

Comments
 (0)