From f37d7358903496c8882cb60df3a4ff00e1bad578 Mon Sep 17 00:00:00 2001 From: Willem Date: Sat, 23 Apr 2016 03:17:50 +0200 Subject: [PATCH] Added jshint --- es5-ff-spa-loader.js | 202 ++++++++++++++++++++++--------------------- package.json | 1 + test/karma.conf.js | 27 +++++- 3 files changed, 129 insertions(+), 101 deletions(-) diff --git a/es5-ff-spa-loader.js b/es5-ff-spa-loader.js index dfcc189..9632ef3 100644 --- a/es5-ff-spa-loader.js +++ b/es5-ff-spa-loader.js @@ -21,7 +21,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* jslint browser: true */ -/* global angular,define,sqlitePlugin */ +/* global angular,define,module,sqlitePlugin */ /** * FFSpaLoader is an assets loader for single page applications. @@ -147,6 +147,18 @@ */ var askUrlSubmitLock = false; + /** + * Prints the debug message with prefix to the options.debug.handler if options.debug.enable is true. + * @param {String} message The message to log. + * @private + */ + var utilDebug = function (message) { + if (options.debug.enable !== true) { + return; + } + options.debug.handler(options.debug.prefix+message); + }; + /** * The factory which contains detection helpers and cache backend builders. */ @@ -290,18 +302,6 @@ } }; - /** - * Prints the debug message with prefix to the options.debug.handler if options.debug.enable is true. - * @param {String} message The message to log. - * @private - */ - var utilDebug = function (message) { - if (options.debug.enable !== true) { - return; - } - options.debug.handler(options.debug.prefix+message); - }; - /** * The default error handler which renders the error in the browser. * @param {Error|String} err The error object or message. @@ -452,7 +452,11 @@ }; var cacheCheckType = function (type, cb, action) { - cacheHasService(type)?action():cb(new Error('No caching for '+type)); + if (cacheHasService(type)) { + action(); + } else { + cb(new Error('No caching for '+type)); + } }; /** @@ -1061,6 +1065,91 @@ }); }; + /** + * Boots angular modules if enabled. + * + * @param {function} cb Error first callback gets called done. + * @private + */ + var bootAngular = function(cb) { + if (options.boot.angular.enable !== true) { + utilDebug('bootAngular disabled by options'); + return cb(null); + } + if (options.boot.angular.modules.length === 0) { + utilDebug('bootAngular disabled by no modules'); + return cb(null); + } + utilDebug('bootAngular start '+options.boot.angular.modules); + angular.bootstrap(document, options.boot.angular.modules); + cb(null); + }; + + /** + * Boot cleanup removed the html tags by id after the timeout. + * + * @private + */ + var bootCleanup = function() { + if (options.boot.cleanup.enable !== true) { + utilDebug('bootCleanup disabled by options'); + return; + } + if (options.boot.cleanup.tags.length === 0) { + utilDebug('bootCleanup disabled by no tags ids.'); + return; + } + utilDebug('bootCleanup after '+options.boot.cleanup.timeout+' ms.'); + setTimeout ( function () { + for (var tagIdx in options.boot.cleanup.tags) { + var tagId = options.boot.cleanup.tags[tagIdx]; + var tag = document.getElementById(tagId); + if (tag !== null) { + tag.parentNode.removeChild(tag); + utilDebug('bootCleanup removed '+tagId); + } + } + }, options.boot.cleanup.timeout); + }; + + /** + * Boots cordova applications which want to use the sqllite plugin as cache. + * Note: On none cordova page it will callback directly. + * Note: On none cordova device page is will timeout if option is set. + * + * @param {function} cb Error first callback gets called device is ready. + * @private + */ + var bootCordova = function(cb) { + if (options.boot.cordova.enable !== true) { + utilDebug('bootCordova disabled by options'); + return cb(null); + } + if (factory.detect.cordova() !== true) { + utilDebug('bootCordova disabled by detect'); + return cb(null); + } + var startTime = new Date().getTime(); + var bootOnce = function() { + var callback = cb; + cb = null; + utilDebug('bootCordova done in '+(new Date().getTime()-startTime)+' ms.'); + callback(null); + }; + if (options.boot.cordova.timeout > 0) { + utilDebug('bootCordova timeout '+options.boot.cordova.timeout); + setTimeout ( function () { + utilDebug('bootCordova timeout'); + bootOnce(); + }, options.boot.cordova.timeout); + } + document.addEventListener('deviceready', function () { + rootWindow[options.boot.cordova.flag] = true; + utilDebug('bootCordova '+options.boot.cordova.flag); + bootOnce(); + }, false); + }; + /** * Starts the loader. * @@ -1179,91 +1268,6 @@ } }; - /** - * Boot cleanup removed the html tags by id after the timeout. - * - * @private - */ - var bootCleanup = function() { - if (options.boot.cleanup.enable !== true) { - utilDebug('bootCleanup disabled by options'); - return; - } - if (options.boot.cleanup.tags.length === 0) { - utilDebug('bootCleanup disabled by no tags ids.'); - return; - } - utilDebug('bootCleanup after '+options.boot.cleanup.timeout+' ms.'); - setTimeout ( function () { - for (var tagIdx in options.boot.cleanup.tags) { - var tagId = options.boot.cleanup.tags[tagIdx]; - var tag = document.getElementById(tagId); - if (tag !== null) { - tag.parentNode.removeChild(tag); - utilDebug('bootCleanup removed '+tagId); - } - } - }, options.boot.cleanup.timeout); - }; - - /** - * Boots angular modules if enabled. - * - * @param {function} cb Error first callback gets called done. - * @private - */ - var bootAngular = function(cb) { - if (options.boot.angular.enable !== true) { - utilDebug('bootAngular disabled by options'); - return cb(null); - } - if (options.boot.angular.modules.length === 0) { - utilDebug('bootAngular disabled by no modules'); - return cb(null); - } - utilDebug('bootAngular start '+options.boot.angular.modules); - angular.bootstrap(document, options.boot.angular.modules); - cb(null); - }; - - /** - * Boots cordova applications which want to use the sqllite plugin as cache. - * Note: On none cordova page it will callback directly. - * Note: On none cordova device page is will timeout if option is set. - * - * @param {function} cb Error first callback gets called device is ready. - * @private - */ - var bootCordova = function(cb) { - if (options.boot.cordova.enable !== true) { - utilDebug('bootCordova disabled by options'); - return cb(null); - } - if (factory.detect.cordova() !== true) { - utilDebug('bootCordova disabled by detect'); - return cb(null); - } - var startTime = new Date().getTime(); - var bootOnce = function() { - var callback = cb; - cb = null; - utilDebug('bootCordova done in '+(new Date().getTime()-startTime)+' ms.'); - callback(null); - }; - if (options.boot.cordova.timeout > 0) { - utilDebug('bootCordova timeout '+options.boot.cordova.timeout); - setTimeout ( function () { - utilDebug('bootCordova timeout'); - bootOnce(); - }, options.boot.cordova.timeout); - } - document.addEventListener('deviceready', function () { - rootWindow[options.boot.cordova.flag] = true; - utilDebug('bootCordova '+options.boot.cordova.flag); - bootOnce(); - }, false); - }; - // Auto fill handlers and return public object. options.debug.handler = function(msg) {console.log(msg);}; options.error.handler = utilErrorHandler; diff --git a/package.json b/package.json index 4dcce17..4073205 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "karma-jasmine": "0.3.8", "karma-phantomjs-launcher": "1.0.0", "karma-requirejs": "0.2.6", + "karma-jshint": "0.1.0", "karma-mocha-reporter": "2.0.1", "karma-junit-reporter": "0.4.2", "angular": "^1.4.8", diff --git a/test/karma.conf.js b/test/karma.conf.js index a2a47e8..cbabc47 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -12,7 +12,7 @@ module.exports = function(config) { 'test/spec-runner.js'], preprocessors: { - 'es5-ff-spa-loader.js': ['coverage'] + 'es5-ff-spa-loader.js': ['jshint','coverage'] }, reporters: ['coverage', 'mocha', 'junit'], @@ -26,12 +26,35 @@ module.exports = function(config) { classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element, properties: {} // key value pair of properties to add to the section of the report }, - + + jshint: { + options: { + curly: true, + eqeqeq: true, + immed: true, + latedef: true, + newcap: true, + noarg: true, + sub: true, + undef: true, + boss: true, + devel: true, + eqnull: true, + browser: true, + globals: { + cordova: true, + jQuery: true + } + }, + summary: true + }, + plugins: [ 'karma-requirejs', 'karma-coverage', 'karma-phantomjs-launcher', 'karma-jasmine', + 'karma-jshint', 'karma-mocha-reporter', 'karma-junit-reporter' ],