Skip to content

Commit 9e5fa00

Browse files
committed
Fix JSHint warnings
Fixes gh-36
1 parent 94d8ddc commit 9e5fa00

File tree

8 files changed

+90
-26
lines changed

8 files changed

+90
-26
lines changed

.jshintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/spec/**
2+
**/node_modules/**
3+
**/packages/**

.jshintrc

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

bootstrap-node.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
3-Clause BSD License
66
https://github.com/motorola-mobility/montage/blob/master/LICENSE.md
77
*/
8-
8+
/*jshint node:true */
99
var Require = require("./require");
1010
require("./node"); // patches Require
1111
var URL = require("url");
@@ -36,8 +36,9 @@ var bootstrap = function () {
3636
};
3737

3838
function findPackage(directory, callback) {
39-
if (directory == PATH.dirname(directory))
39+
if (directory === PATH.dirname(directory)) {
4040
return callback("Can't find package");
41+
}
4142
var packageJson = PATH.join(directory, "package.json");
4243
FS.stat(packageJson, function (error, stat) {
4344
if (error || !stat.isFile()) {
@@ -82,7 +83,7 @@ var loadFreeModule = function (program, command, args) {
8283
.done();
8384
};
8485

85-
if (require.main == module) {
86+
if (require.main === module) {
8687
bootstrap();
8788
}
8889

bootstrap.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"promise": "packages/q/q.js"
3131
};
3232

33+
/*jshint -W089 */
3334
if (!global.preload) {
3435
for (var id in pending) {
3536
load(pending[id]);
@@ -42,7 +43,7 @@
4243
global.bootstrap = function (id, factory) {
4344
definitions[id] = factory;
4445
delete pending[id];
45-
for (var id in pending) {
46+
for (id in pending) {
4647
// this causes the function to exit if there are any remaining
4748
// scripts loading, on the first iteration. consider it
4849
// equivalent to an array length check
@@ -53,6 +54,7 @@
5354
delete global.bootstrap;
5455
allModulesLoaded();
5556
};
57+
/*jshint +W089 */
5658

5759
// one module loaded for free, for use in require.js, browser.js
5860
global.bootstrap("mini-url", function (require, exports) {
@@ -108,14 +110,18 @@
108110
if (mrLocation) {
109111
if (script.dataset) {
110112
for (name in script.dataset) {
111-
params[name] = script.dataset[name];
113+
if (script.dataset.hasOwnProperty(name)) {
114+
params[name] = script.dataset[name];
115+
}
112116
}
113117
} else if (script.attributes) {
114118
var dataRe = /^data-(.*)$/,
115119
letterAfterDash = /-([a-z])/g,
120+
/*jshint -W083 */
116121
upperCaseChar = function (_, c) {
117122
return c.toUpperCase();
118123
};
124+
/*jshint +W083 */
119125

120126
for (j = 0; j < script.attributes.length; j++) {
121127
attr = script.attributes[j];
@@ -245,7 +251,7 @@
245251
location: applicationLocation,
246252
hash: params.applicationHash
247253
})
248-
.invoke('async', moduleId)
254+
.invoke('async', moduleId);
249255
});
250256

251257
})

browser.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
44
(c) Copyright 2012 Motorola Mobility, Inc. All Rights Reserved.
55
</copyright> */
6-
/*global bootstrap */
6+
/*global bootstrap,montageDefine:true */
7+
/*jshint -W015, evil:true, camelcase:false */
78
bootstrap("require/browser", function (require) {
89

910
var Require = require("require");
@@ -90,10 +91,12 @@ var __FILE__String = "__FILE__",
9091

9192
Require.Compiler = function (config) {
9293
return function(module) {
93-
if (module.factory || module.text === void 0)
94+
if (module.factory || module.text === void 0) {
9495
return module;
95-
if (config.useScriptInjection)
96+
}
97+
if (config.useScriptInjection) {
9698
throw new Error("Can't use eval.");
99+
}
97100

98101
// Here we use a couple tricks to make debugging better in various browsers:
99102
// TODO: determine if these are all necessary / the best options
@@ -118,7 +121,7 @@ Require.Compiler = function (config) {
118121
// module.factory = new Function("require", "exports", "module", module.text + "\n//*/"+sourceURLComment);
119122

120123
module.factory.displayName = displayName;
121-
}
124+
};
122125
};
123126

124127
Require.XhrLoader = function (config) {
@@ -177,12 +180,14 @@ Require.ScriptLoader = function (config) {
177180
return getDefinition(hash, module.id).promise;
178181
})
179182
.then(function (definition) {
183+
/*jshint -W089 */
180184
delete definitions[hash][module.id];
181185
for (var name in definition) {
182186
module[name] = definition[name];
183187
}
184188
module.location = location;
185189
module.directory = URL.resolve(location, ".");
190+
/*jshint +W089 */
186191
});
187192
};
188193
};

node.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
3-Clause BSD License
66
https://github.com/motorola-mobility/montage/blob/master/LICENSE.md
77
*/
8-
8+
/*jshint node:true */
99
var Require = require("./require");
1010
var Promise = require("q");
1111
var FS = require("fs");
@@ -100,7 +100,7 @@ Require.NodeLoader = function NodeLoader(config) {
100100
type: "native",
101101
exports: require(id),
102102
location: location
103-
}
103+
};
104104
};
105105
};
106106

@@ -124,8 +124,9 @@ Require.makeLoader = function makeLoader(config) {
124124
};
125125

126126
Require.findPackagePath = function findPackagePath(directory) {
127-
if (directory == PATH.dirname(directory))
127+
if (directory === PATH.dirname(directory)) {
128128
return Promise.reject(new Error("Can't find package"));
129+
}
129130
var packageJson = PATH.join(directory, "package.json");
130131
return Promise.ninvoke(FS, "stat", packageJson)
131132
.then(function (stat) {
@@ -151,7 +152,7 @@ Require.findPackageLocationAndModuleId = function findPackageLocationAndModuleId
151152
return {
152153
location: Require.directoryPathToLocation(packageDirectory),
153154
id: modulePath
154-
}
155+
};
155156
}, function (error) {
156157
throw new Error("Can't find package: " + path);
157158
});

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"main": "require",
1414
"scripts": {
15-
"test": "node spec/phantom.js"
15+
"test": "node spec/phantom.js && jshint ."
1616
},
1717
"bin": {
1818
"mr": "bin/mr"
@@ -31,7 +31,8 @@
3131
"wd": "~0.0.31",
3232
"joey": "~0.1.3",
3333
"istanbul": "~0.1.34",
34-
"q-io": "~1.6.4"
34+
"q-io": "~1.6.4",
35+
"jshint": "~2.1.4"
3536
},
3637
"exclude": [
3738
"README.md",

require.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444

4545
})(function (Require, Promise, URL) {
4646

47-
if (!this)
47+
if (!this) {
4848
throw new Error("Require does not work in strict mode.");
49+
}
4950

5051
var globalEval = eval; // reassigning causes eval to not use lexical scope.
5152

@@ -139,8 +140,9 @@
139140
// data-lock on a cycle of dependencies.
140141
loading = loading || {};
141142
// has this all happened before? will it happen again?
142-
if (has(loading, topId))
143+
if (has(loading, topId)) {
143144
return; // break the cycle of violence.
145+
}
144146
loading[topId] = true; // this has happened before
145147
return load(topId, viaId)
146148
.then(function () {
@@ -234,20 +236,23 @@
234236
// too much performance evil for one function.
235237
function identify(id2, require2, seen) {
236238
var location = config.location;
237-
if (require2.location === location)
239+
if (require2.location === location) {
238240
return id2;
241+
}
239242

240243
var internal = !!seen;
241244
seen = seen || {};
242-
if (has(seen, location))
245+
if (has(seen, location)) {
243246
return null; // break the cycle of violence.
247+
}
244248
seen[location] = true;
245-
249+
/*jshint -W089 */
246250
for (var name in config.mappings) {
247251
var mapping = config.mappings[name];
248252
location = mapping.location;
249-
if (!config.hasPackage(location))
253+
if (!config.hasPackage(location)) {
250254
continue;
255+
}
251256
var candidate = config.getPackage(location);
252257
var id1 = candidate.identify(id2, require2, seen);
253258
if (id1 === null) {
@@ -265,6 +270,7 @@
265270
"Can't identify " + id2 + " from " + require2.location
266271
);
267272
}
273+
/*jshint +W089 */
268274
}
269275

270276
// Creates a unique require function for each module that encapsulates
@@ -387,7 +393,7 @@
387393
try {
388394
return JSON.parse(json);
389395
} catch (error) {
390-
error.message = error.message + " in " + JSON.stringify(descriptionLocation)
396+
error.message = error.message + " in " + JSON.stringify(descriptionLocation);
391397
throw error;
392398
}
393399
});
@@ -409,8 +415,9 @@
409415

410416
config.hasPackage = function (dependency) {
411417
dependency = normalizeDependency(dependency, config);
412-
if (!dependency.location)
418+
if (!dependency.location) {
413419
return false;
420+
}
414421
var location = dependency.location;
415422
return !!loadedPackages[location];
416423
};
@@ -494,8 +501,9 @@
494501
dependency.name + "/"
495502
);
496503
}
497-
if (!dependency.location)
504+
if (!dependency.location) {
498505
return dependency; // partially completed
506+
}
499507
// make sure the dependency location has a trailing slash so that
500508
// relative urls will resolve properly
501509
if (!/\/$/.test(dependency.location)) {
@@ -550,12 +558,14 @@
550558
var overlay = description.overlay || {};
551559
var layer;
552560
(config.overlays || Require.overlays).forEach(function (engine) {
561+
/*jshint -W089 */
553562
if (overlay[engine]) {
554563
var layer = overlay[engine];
555564
for (var name in layer) {
556565
description[name] = layer[name];
557566
}
558567
}
568+
/*jshint +W089 */
559569
});
560570
delete description.overlay;
561571

@@ -611,8 +621,9 @@
611621
// dependencies, devDependencies if not in production
612622
[description.dependencies, !config.production ? description.devDependencies : null]
613623
.forEach(function (dependencies) {
614-
if (!dependencies)
624+
if (!dependencies) {
615625
return;
626+
}
616627
Object.keys(dependencies).forEach(function (name) {
617628
if (!mappings[name]) {
618629
// dependencies are equivalent to name and version mappings,
@@ -656,6 +667,7 @@
656667
source.unshift.apply(source, parts);
657668
}
658669
for (var i = 0, ii = source.length; i < ii; i++) {
670+
/*jshint -W035 */
659671
var part = source[i];
660672
if (part === "" || part === ".") {
661673
} else if (part === "..") {
@@ -665,6 +677,7 @@
665677
} else {
666678
target.push(part);
667679
}
680+
/*jshint +W035 */
668681
}
669682
return target.join("/");
670683
}
@@ -804,10 +817,12 @@
804817
id.indexOf(prefix) === 0 &&
805818
id.charAt(prefix.length) === "/"
806819
) {
820+
/*jshint -W083 */
807821
var mapping = mappings[prefix];
808822
var rest = id.slice(prefix.length + 1);
809823
return config.loadPackage(mapping, config)
810824
.then(function (mappingRequire) {
825+
/*jshint +W083 */
811826
module.mappingRedirect = rest;
812827
module.mappingRequire = mappingRequire;
813828
return mappingRequire.deepLoad(rest, config.location);

0 commit comments

Comments
 (0)