diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..66b8957d --- /dev/null +++ b/.jshintrc @@ -0,0 +1,13 @@ +{ + "esversion": 5, + "freeze": true, + "futurehostile": true, + "noarg": true, + "nonbsp": true, + "nonew": true, + "strict": "implied", + "undef": true, + "validthis": true, + "browser": true, + "node": true +} diff --git a/Gruntfile.js b/Gruntfile.js index 9e7834dd..4855aacb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,7 +27,7 @@ module.exports = function (grunt) { var apiServer = require("./build/api-gen/dynamic-server.js"); function runApiServer() { - var done = this.async(); + this.async(); apiServer(grunt, "./build/api.json"); setTimeout(function(){ open("http://localhost:8080"); @@ -107,19 +107,19 @@ module.exports = function (grunt) { }, jshint: { + options: { + jshintrc: true + }, misc: ['Gruntfile.js'], src: ['src/**/*.js'], - tests: ['tests/**/*.js'], - options: { - trailing: true, - ignores: ['tests/lib/*.js'], - globals: { - } - } + tests: ['tests/**/*.js', '!tests/lib/**/*.js'] }, qunit: { + options: { + noGlobals: true + }, browser: ['tests/index.html'] }, diff --git a/package.json b/package.json index dd980a68..448cef0a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "grunt-banner": "^0.6.0", "grunt-browserify": "^4.0.1", "grunt-contrib-connect": "^0.11.2", - "grunt-contrib-jshint": "^0.11.3", + "grunt-contrib-jshint": "^1.0.0", "grunt-contrib-qunit": "^0.7.0", "grunt-contrib-uglify": "^0.11.0", "grunt-contrib-watch": "^0.6.1", diff --git a/src/core/animation.js b/src/core/animation.js index 585417cd..78d1aad5 100644 --- a/src/core/animation.js +++ b/src/core/animation.js @@ -1,3 +1,6 @@ +var Crafty = require('../core/core.js'); + + /**@ * #Crafty.easing * @category Animation diff --git a/src/core/core.js b/src/core/core.js index 8cf12f8b..0254d207 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -1469,7 +1469,7 @@ Crafty.extend({ step: function () { var drawTimeStart, dt, lastFrameTime, loops = 0; - currentTime = new Date().getTime(); + var currentTime = new Date().getTime(); if (endTime > 0) Crafty.trigger("MeasureWaitTime", currentTime - endTime); @@ -2015,7 +2015,7 @@ function clone(obj) { // export Crafty if (typeof define === 'function') { // AMD - define('crafty', [], function () { + define('crafty', [], function () { // jshint ignore:line return Crafty; }); } diff --git a/src/core/extensions.js b/src/core/extensions.js index 3482970f..9889fe41 100644 --- a/src/core/extensions.js +++ b/src/core/extensions.js @@ -1,4 +1,4 @@ -var Crafty = require('./core'); +var Crafty = require('../core/core.js'); var document = (typeof window !== "undefined") && window.document; /**@ diff --git a/src/core/model.js b/src/core/model.js index 07eba3c5..1a54c7d3 100644 --- a/src/core/model.js +++ b/src/core/model.js @@ -1,3 +1,6 @@ +var Crafty = require('../core/core.js'); + + /**@ * #Model * @category Model diff --git a/src/core/systems.js b/src/core/systems.js index d4507263..b3faf241 100644 --- a/src/core/systems.js +++ b/src/core/systems.js @@ -68,7 +68,7 @@ Crafty._registerLazySystem = function(name, obj) { // Each system has its properties and methods copied onto an object of this type Crafty.CraftySystem = (function(){ - systemID = 1; + var systemID = 1; return function(name, template) { this.name = name; if (!template) return this; diff --git a/src/core/tween.js b/src/core/tween.js index 0c70f386..f17eebf5 100644 --- a/src/core/tween.js +++ b/src/core/tween.js @@ -1,3 +1,6 @@ +var Crafty = require('../core/core.js'); + + /**@ * #Tween * @category Animation diff --git a/src/graphics/viewport.js b/src/graphics/viewport.js index b8e376d4..b228a9b0 100644 --- a/src/graphics/viewport.js +++ b/src/graphics/viewport.js @@ -460,7 +460,7 @@ Crafty.extend({ var active = false, dragging = false, lastMouse = {}; - old = {}; + function stopLook(){ dragging = false; } @@ -481,7 +481,7 @@ Crafty.extend({ case 'move': case 'drag': if (!dragging) return; - diff = { + var diff = { x: arg.clientX - lastMouse.x, y: arg.clientY - lastMouse.y }; diff --git a/src/graphics/webgl-layer.js b/src/graphics/webgl-layer.js index 50cbd272..269c4721 100644 --- a/src/graphics/webgl-layer.js +++ b/src/graphics/webgl-layer.js @@ -2,7 +2,7 @@ var Crafty = require('../core/core.js'), document = window.document; // Object for abstracting out all the gl calls to handle rendering entities with a particular program -RenderProgramWrapper = function(layer, shader){ +function RenderProgramWrapper(layer, shader){ this.shader = shader; this.layer = layer; this.context = layer.context; @@ -12,7 +12,7 @@ RenderProgramWrapper = function(layer, shader){ this.max_size = 1024; this._indexArray = new Uint16Array(6 * this.array_size); this._indexBuffer = layer.context.createBuffer(); -}; +} RenderProgramWrapper.prototype = { // Takes an array of attributes; see WebGLLayer's getProgramWrapper method diff --git a/src/isometric/diamond-iso.js b/src/isometric/diamond-iso.js index 349ceba9..a53675f5 100644 --- a/src/isometric/diamond-iso.js +++ b/src/isometric/diamond-iso.js @@ -113,7 +113,7 @@ Crafty.extend({ var len = this._tiles[_x][_y].length; for(var _z=0; _z0 && x0 && y0 && x0 && y 0) throw "Unexpected number of arguments for Matrix2D()"; - }; // class Matrix2D + } // class Matrix2D Matrix2D.prototype.a = 1; Matrix2D.prototype.b = 0; diff --git a/tests/.jshintrc b/tests/.jshintrc new file mode 100644 index 00000000..384f9a63 --- /dev/null +++ b/tests/.jshintrc @@ -0,0 +1,10 @@ +{ + "extends": "../.jshintrc", + "qunit": true, + "globals": { + "Crafty": false, + "createTouchEvent": false, + "Round": false, + "resetStage": false + } +} diff --git a/tests/audio.js b/tests/audio.js index 762f1cb5..8e4d16c9 100644 --- a/tests/audio.js +++ b/tests/audio.js @@ -16,7 +16,7 @@ this.endedListeners.push(listener); break; default: - throw new Exception("Not implemented"); + throw("Not implemented"); } }; this.removeEventListener = function(event, listener) { @@ -26,7 +26,7 @@ if (ind) this.endedListeners.splice(ind, 1); break; default: - throw new Exception("Not implemented"); + throw("Not implemented"); } }; diff --git a/tests/common.js b/tests/common.js index 2a4bb36e..c547d3b3 100644 --- a/tests/common.js +++ b/tests/common.js @@ -1,15 +1,17 @@ -//////////////////////// -/// Helper functions /// -//////////////////////// +////////////////////// +// Helper functions // +////////////////////// -resetStage = function() { +var global = typeof GLOBAL !== 'undefined' ? GLOBAL : window; + +global.resetStage = function() { Crafty.viewport.reset(); Crafty.viewport.scroll('_x', 0); Crafty.viewport.scroll('_y', 0); Crafty.viewport.clampToEntities = true; }; -Round = function(x){ +global.Round = function(x){ return Math.round(x*100)/100; }; @@ -23,6 +25,7 @@ QUnit.testDone(function() { }); QUnit.config.hidepassed = true; +QUnit.config.reorder = false; /////////////////////// // OpenSauce logging // diff --git a/tests/index-headless.js b/tests/index-headless.js index cf52f4d3..ea35d430 100644 --- a/tests/index-headless.js +++ b/tests/index-headless.js @@ -1,5 +1,5 @@ /** CRAFTY-JS **/ -Crafty = require('../src/crafty-headless.js')(); +GLOBAL.Crafty = require('../src/crafty-headless.js')(); Crafty.init(); /** COMMON TEST CODE **/ diff --git a/tests/lib/.jshintignore b/tests/lib/.jshintignore new file mode 100644 index 00000000..a02ac9f8 --- /dev/null +++ b/tests/lib/.jshintignore @@ -0,0 +1 @@ +This directory and all subdirectories will not be validated by jshint. diff --git a/tests/webdriver/.jshintrc b/tests/webdriver/.jshintrc new file mode 100644 index 00000000..a7367a36 --- /dev/null +++ b/tests/webdriver/.jshintrc @@ -0,0 +1,8 @@ +{ + "extends": "../.jshintrc", + "globals": { + "browser": false, + "signalBarrier": false, + "waitBarrier": false + } +} diff --git a/tests/webdriver/common.js b/tests/webdriver/common.js index 9a32b842..96d37b45 100644 --- a/tests/webdriver/common.js +++ b/tests/webdriver/common.js @@ -9,8 +9,8 @@ window.addEventListener('load', function() { }; // wait for webdriver signal - window.barrierCallbacks = {}; - window.barrierSignals = {}; + var barrierCallbacks = window.barrierCallbacks = {}; + var barrierSignals = window.barrierSignals = {}; window.waitBarrier = function(label, callback) { if (barrierSignals[label]) { // signal already received, trigger callback immediately callback.call(null);