diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..6bf48bf0 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,9 @@ +{ + "bitwise": true, + "curly": true, + "freeze": true, + "immed": true, + "newcap": true, + "trailing": true, + "loopfunc": true +} \ No newline at end of file diff --git a/grunt/config/jshint.js b/grunt/config/jshint.js index 0a549550..253c739d 100644 --- a/grunt/config/jshint.js +++ b/grunt/config/jshint.js @@ -5,13 +5,7 @@ module.exports = { 'lib/jasmine-core/jasmine.js' ], options: { - /* While it's possible that we could be considering unwanted prototype methods, mostly - * we're doing this because the objects are being used as maps. - */ - forin: false, - - /* We're fine with functions defined inside loops (setTimeout functions, etc) */ - loopfunc: true + jshintrc: '.jshintrc' }, all: ['src/**/*.js'] }; diff --git a/package.json b/package.json index bdadbc52..8918dc04 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "version": "2.0.0-rc3", "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.2.0", - "grunt-contrib-concat": "~0.1.3", - "grunt-contrib-compass": "~0.1.3", - "grunt-contrib-compress": "~0.4.1", - "shelljs": "~0.1.2" + "grunt-contrib-jshint": "~0.7.0", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-compass": "~0.6.0", + "grunt-contrib-compress": "~0.5.2", + "shelljs": "~0.1.4" } } diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 31e953f5..4029a225 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -47,8 +47,8 @@ getJasmineRequireObj().pp = function(j$) { PrettyPrinter.prototype.iterateObject = function(obj, fn) { for (var property in obj) { - if (!obj.hasOwnProperty(property)) continue; - if (property == '__Jasmine_been_here_before__') continue; + if (!obj.hasOwnProperty(property)) { continue; } + if (property == '__Jasmine_been_here_before__') { continue; } fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && obj.__lookupGetter__(property) !== null) : false); } diff --git a/src/core/ReportDispatcher.js b/src/core/ReportDispatcher.js index be4e3db2..64454f0c 100644 --- a/src/core/ReportDispatcher.js +++ b/src/core/ReportDispatcher.js @@ -5,11 +5,11 @@ getJasmineRequireObj().ReportDispatcher = function() { for (var i = 0; i < dispatchedMethods.length; i++) { var method = dispatchedMethods[i]; - this[method] = function(m) { + this[method] = (function(m) { return function() { dispatch(m, arguments); }; - }(method); + }(method)); } var reporters = []; diff --git a/src/core/Spec.js b/src/core/Spec.js index 450dc7b5..65ba928b 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -67,8 +67,8 @@ getJasmineRequireObj().Spec = function(j$) { } var befores = this.beforeFns() || [], - afters = this.afterFns() || [], - thisOne = (this.fn.length) ? timeoutable(this.fn) : this.fn; + afters = this.afterFns() || [], + thisOne = (this.fn.length) ? timeoutable(this.fn) : this.fn; var allFns = befores.concat(thisOne).concat(afters); this.queueRunner({ @@ -78,18 +78,18 @@ getJasmineRequireObj().Spec = function(j$) { }); function onException(e) { - if (Spec.isPendingSpecException(e)) { - self.pend(); - return; - } + if (Spec.isPendingSpecException(e)) { + self.pend(); + return; + } - self.addExpectationResult(false, { - matcherName: "", - passed: false, - expected: "", - actual: "", - error: e - }); + self.addExpectationResult(false, { + matcherName: "", + passed: false, + expected: "", + actual: "", + error: e + }); } function complete() { diff --git a/src/core/base.js b/src/core/base.js index d36326b3..998bbd61 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -51,18 +51,18 @@ getJasmineRequireObj().base = function(j$) { j$.createSpy = function(name, originalFn) { var spyStrategy = new j$.SpyStrategy({ - name: name, - fn: originalFn, - getSpy: function() { return spy; } - }), - callTracker = new j$.CallTracker(), - spy = function() { - callTracker.track({ - object: this, - args: Array.prototype.slice.apply(arguments) - }); - return spyStrategy.exec.apply(this, arguments); - }; + name: name, + fn: originalFn, + getSpy: function() { return spy; } + }), + callTracker = new j$.CallTracker(), + spy = function() { + callTracker.track({ + object: this, + args: Array.prototype.slice.apply(arguments) + }); + return spyStrategy.exec.apply(this, arguments); + }; for (var prop in originalFn) { if (prop === 'and' || prop === 'calls') { @@ -83,7 +83,7 @@ getJasmineRequireObj().base = function(j$) { return false; } return putativeSpy.and instanceof j$.SpyStrategy && - putativeSpy.calls instanceof j$.CallTracker; + putativeSpy.calls instanceof j$.CallTracker; }; j$.createSpyObj = function(baseName, methodNames) { diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index a40f07d1..e5121fdd 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -37,7 +37,9 @@ getJasmineRequireObj().matchersUtil = function(j$) { if (expected.length > 0) { for (var i = 0; i < expected.length; i++) { - if (i > 0) message += ","; + if (i > 0) { + message += ","; + } message += " " + j$.pp(expected[i]); } } @@ -85,11 +87,11 @@ getJasmineRequireObj().matchersUtil = function(j$) { // Identical objects are equal. `0 === -0`, but they aren't identical. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). - if (a === b) return a !== 0 || 1 / a == 1 / b; + if (a === b) { return a !== 0 || 1 / a == 1 / b; } // A strict comparison is necessary because `null == undefined`. - if (a === null || b === null) return a === b; + if (a === null || b === null) { return a === b; } var className = Object.prototype.toString.call(a); - if (className != Object.prototype.toString.call(b)) return false; + if (className != Object.prototype.toString.call(b)) { return false; } switch (className) { // Strings, numbers, dates, and booleans are compared by value. case '[object String]': @@ -113,14 +115,14 @@ getJasmineRequireObj().matchersUtil = function(j$) { a.multiline == b.multiline && a.ignoreCase == b.ignoreCase; } - if (typeof a != 'object' || typeof b != 'object') return false; + if (typeof a != 'object' || typeof b != 'object') { return false; } // Assume equality for cyclic structures. The algorithm for detecting cyclic // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. var length = aStack.length; while (length--) { // Linear search. Performance is inversely proportional to the number of // unique nested structures. - if (aStack[length] == a) return bStack[length] == b; + if (aStack[length] == a) { return bStack[length] == b; } } // Add the first object to the stack of traversed objects. aStack.push(a); @@ -134,7 +136,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { if (result) { // Deep compare the contents, ignoring non-numeric properties. while (size--) { - if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) break; + if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } } } } else { @@ -151,13 +153,13 @@ getJasmineRequireObj().matchersUtil = function(j$) { // Count the expected number of properties. size++; // Deep compare each member. - if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) break; + if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; } } } // Ensure that both objects contain the same number of properties. if (result) { for (key in b) { - if (has(b, key) && !(size--)) break; + if (has(b, key) && !(size--)) { break; } } result = !size; } diff --git a/src/core/util.js b/src/core/util.js index 489ca730..5285b8d7 100644 --- a/src/core/util.js +++ b/src/core/util.js @@ -3,14 +3,16 @@ getJasmineRequireObj().util = function() { var util = {}; util.inherit = function(childClass, parentClass) { - var subclass = function() { + var Subclass = function() { }; - subclass.prototype = parentClass.prototype; - childClass.prototype = new subclass(); + Subclass.prototype = parentClass.prototype; + childClass.prototype = new Subclass(); }; util.htmlEscape = function(str) { - if (!str) return str; + if (!str) { + return str; + } return str.replace(/&/g, '&') .replace(//g, '>'); @@ -18,7 +20,9 @@ getJasmineRequireObj().util = function() { util.argsToArray = function(args) { var arrayOfArgs = []; - for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); + for (var i = 0; i < args.length; i++) { + arrayOfArgs.push(args[i]); + } return arrayOfArgs; }; diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 169f67f8..1d5439d4 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -1,8 +1,8 @@ jasmineRequire.HtmlReporter = function(j$) { var noopTimer = { - start: function(){}, - elapsed: function(){ return 0; } + start: function() {}, + elapsed: function() { return 0; } }; function HtmlReporter(options) { @@ -73,7 +73,8 @@ jasmineRequire.HtmlReporter = function(j$) { symbols.appendChild(createDom("li", { className: result.status, id: "spec_" + result.id, - title: result.fullName} + title: result.fullName + } )); if (result.status == "failed") {