diff --git a/.jshintrc b/.jshintrc index 4b93fa8902..27c028d099 100644 --- a/.jshintrc +++ b/.jshintrc @@ -13,6 +13,7 @@ "noempty": true, "nonstandard": true, "onecase": true, + "sub": true, "regexdash": true, "trailing": true, "undef": true, diff --git a/Gruntfile.js b/Gruntfile.js index 47c4e3dd27..b7bb12257b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,12 +29,9 @@ module.exports = function(grunt) { grunt.config.set('compress', require('./grunt/config/compress')); Object.keys(grunt.file.readJSON('package.json').devDependencies) - .filter(function(npmTaskName){ return npmTaskName.indexOf('grunt-') === 0;}) - .filter(function(npmTaskName){ return npmTaskName != 'grunt-cli' }) - .forEach(function(npmTaskName){ - grunt.loadNpmTasks(npmTaskName); - }) - ; + .filter(function(npmTaskName) { return npmTaskName.indexOf('grunt-') === 0; }) + .filter(function(npmTaskName) { return npmTaskName != 'grunt-cli'; }) + .forEach(function(npmTaskName) { grunt.loadNpmTasks(npmTaskName); }); // Alias 'jshint' to 'lint' to better match the workflow we know grunt.registerTask('lint', ['jshint']); diff --git a/grunt/config/server.js b/grunt/config/server.js index 3e43e07f7c..6227c8e714 100644 --- a/grunt/config/server.js +++ b/grunt/config/server.js @@ -1,17 +1,27 @@ -module.exports = function(grunt){ +'use strict'; + +module.exports = function(grunt) { function testResultLoggerMiddleware(req, res, next) { - if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) return next(); + if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) { + return next(); + } var logType = 'writeln'; var message = req.body; if (req.body.type && req.body.message){ - if (req.body.type == 'error') logType = 'error'; - else if (req.body.message.indexOf('ok') === 0) logType = 'ok'; - else if (req.body.message.indexOf('not ok') === 0) logType = 'error'; + if (req.body.type == 'error') { + logType = 'error'; + } else if (req.body.message.indexOf('ok') === 0) { + logType = 'ok'; + } else if (req.body.message.indexOf('not ok') === 0) { + logType = 'error'; + } message = req.body.message; } - if (typeof message != 'string') message = JSON.stringify(message, null, 2); + if (typeof message != 'string') { + message = JSON.stringify(message, null, 2); + } grunt.log[logType]('[%s][%s]', req.headers['user-agent'], Date.now(), message); res.write(''); res.end('Got it, thanks!'); @@ -24,14 +34,14 @@ module.exports = function(grunt){ hostname: '*', port: 9999, middleware: function(connect, options) { - - connect.logger.token('user-agent', function(req, res){ return req.headers['user-agent']; }); - connect.logger.token('timestamp', function(req, res){ return Date.now(); }); - + + connect.logger.token('user-agent', function(req, res) { return req.headers['user-agent']; }); + connect.logger.token('timestamp', function(req, res) { return Date.now(); }); + return [ connect.json(), testResultLoggerMiddleware, - + connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}), connect.static(options.base), connect.directory(options.base) @@ -39,5 +49,5 @@ module.exports = function(grunt){ }, } } - } -} + }; +}; diff --git a/grunt/config/webdriver-jasmine.js b/grunt/config/webdriver-jasmine.js index 2859da9d66..fd4548595c 100644 --- a/grunt/config/webdriver-jasmine.js +++ b/grunt/config/webdriver-jasmine.js @@ -1,3 +1,5 @@ +'use strict'; + var grunt = require('grunt'); @@ -14,9 +16,11 @@ exports.local = { onError: function(error){ grunt.fatal(error); } -} +}; -if (grunt.option('debug')) exports.local.url += '?debug=' + grunt.option('debug'); +if (grunt.option('debug')) { + exports.local.url += '?debug=' + grunt.option('debug'); +} exports.saucelabs = { @@ -43,7 +47,7 @@ exports.saucelabs = { }, onComplete: exports.local.onComplete, onError: exports.local.onError -} +}; /* https://saucelabs.com/docs/platforms */ exports.saucelabs_ios = @@ -74,7 +78,7 @@ exports.saucelabs_ie10 = sauceItUp({ browserName: 'internet explorer', version: exports.saucelabs_ie11 = sauceItUp({ browserName: 'internet explorer', version: 11, platform:'Windows 8.1' }); -function sauceItUp(desiredCapabilities){ +function sauceItUp(desiredCapabilities) { desiredCapabilities["build"] = exports.saucelabs.desiredCapabilities["build"]; desiredCapabilities["tunnel-identifier"] = exports.saucelabs.desiredCapabilities["tunnel-identifier"]; return { diff --git a/grunt/tasks/populist.js b/grunt/tasks/populist.js index eba314d91e..034e97b3a6 100644 --- a/grunt/tasks/populist.js +++ b/grunt/tasks/populist.js @@ -1,7 +1,7 @@ 'use strict'; var grunt = require('grunt'); -var fs = require('fs') +var fs = require('fs'); module.exports = function() { var config = this.data; diff --git a/grunt/tasks/sauce-tunnel.js b/grunt/tasks/sauce-tunnel.js index c35b631fa2..b762a22a95 100644 --- a/grunt/tasks/sauce-tunnel.js +++ b/grunt/tasks/sauce-tunnel.js @@ -1,16 +1,21 @@ +'use strict'; + var grunt = require('grunt'); var SauceTunnel = require('sauce-tunnel'); -module.exports = function(){ +module.exports = function() { var task = this; - var config = task.data; var shouldStayAliveForever = task.flags.keepalive; var SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY; - if (!SAUCE_ACCESS_KEY) grunt.fatal('Requires the environment variable SAUCE_ACCESS_KEY to be set'); + if (!SAUCE_ACCESS_KEY) { + grunt.fatal('Requires the environment variable SAUCE_ACCESS_KEY to be set'); + } var SAUCE_USERNAME = process.env.SAUCE_USERNAME; - if (!SAUCE_USERNAME) grunt.fatal('Requires the environment variable SAUCE_USERNAME to be set'); + if (!SAUCE_USERNAME) { + grunt.fatal('Requires the environment variable SAUCE_USERNAME to be set'); + } var IDENTIFIER = process.env.TRAVIS_JOB_NUMBER || 'my awesome tunnel'; @@ -28,7 +33,7 @@ module.exports = function(){ stunnel.on('verbose:writeln', grunt.verbose.writeln.bind(grunt.verbose)); stunnel.openTunnel(function(isOpen){ - if (shouldStayAliveForever && isOpen){ + if (shouldStayAliveForever && isOpen) { grunt.verbose.writeln('Keeping the sauce-tunnel open forever because you used the keepalive flag `' + task.nameArgs + '`'); return; } diff --git a/grunt/tasks/webdriver-jasmine.js b/grunt/tasks/webdriver-jasmine.js index 29e54d2d87..5d8b224476 100644 --- a/grunt/tasks/webdriver-jasmine.js +++ b/grunt/tasks/webdriver-jasmine.js @@ -1,3 +1,7 @@ +/* jshint evil: true */ + +'use strict'; + var grunt = require("grunt"); var wd = require('wd'); @@ -6,10 +10,14 @@ module.exports = function(){ var taskSucceeded = this.async(); var desiredCapabilities = {}; - if (config.desiredCapabilities) Object.keys(config.desiredCapabilities).forEach(function(key){ - if (config.desiredCapabilities[key] === undefined) return; - desiredCapabilities[key] = config.desiredCapabilities[key]; - }); + if (config.desiredCapabilities) { + Object.keys(config.desiredCapabilities).forEach(function(key) { + if (config.desiredCapabilities[key] === undefined) { + return; + } + desiredCapabilities[key] = config.desiredCapabilities[key]; + }); + } grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities)); var browser = wd.promiseChainRemote(config.webdriver.remote); @@ -37,26 +45,31 @@ module.exports = function(){ return browser .eval('document.documentElement.innerText || document.documentElement.textContent') .then(grunt.verbose.writeln.bind(grunt.verbose)) - .then(function(){throw error}) + .then(function(){ throw error; }) ; }) .finally(function(){ - if (grunt.option('webdriver-keep-open')) return; + if (grunt.option('webdriver-keep-open')) { + return; + } grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.'); return browser.quit(); }) .done( - function(){ - if (config.onComplete) config.onComplete(results); + function() { + if (config.onComplete) { + config.onComplete(results); + } taskSucceeded(true); }, - function(error){ - if (config.onError) config.onError(error); + function(error) { + if (config.onError) { + config.onError(error); + } taskSucceeded(false); } - ) - ; -} + ); +}; function getJSReport(browser){ return browser @@ -66,6 +79,5 @@ function getJSReport(browser){ }) .waitForCondition("typeof window.jasmine.getJSReport != 'undefined'", 10e3) .waitForCondition("window.postDataToURL.running <= 0", 30e3) - .eval("jasmine.getJSReport().passed") - ; + .eval("jasmine.getJSReport().passed"); } diff --git a/grunt/tasks/webdriver-phantomjs.js b/grunt/tasks/webdriver-phantomjs.js index 0f841b633e..4612e788ee 100644 --- a/grunt/tasks/webdriver-phantomjs.js +++ b/grunt/tasks/webdriver-phantomjs.js @@ -1,3 +1,5 @@ +'use strict'; + var grunt = require('grunt'); module.exports = function(){ @@ -21,7 +23,9 @@ module.exports = function(){ }); child.on('exit', function(code) { grunt.verbose.writeln('phantomjs END'); - if (code) grunt.fatal('phantomjs FAIL'); + if (code) { + grunt.fatal('phantomjs FAIL'); + } }); function verboseWrite(chunk) { @@ -34,4 +38,4 @@ module.exports = function(){ } child.stdout.on('data', verboseWrite); child.stderr.on('data', verboseWrite); -} +}; diff --git a/src/.jshintrc b/src/.jshintrc index 14c11e85a9..6f88458a71 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -15,6 +15,7 @@ "nonstandard": true, "onecase": true, "regexdash": true, + "sub": false, "trailing": true, "undef": true, "unused": "vars",