From 9f15cad438aff9294b44b1769d4f55f1384544c0 Mon Sep 17 00:00:00 2001 From: Tim Martin Date: Sat, 22 Sep 2018 14:27:35 -0400 Subject: [PATCH] Fix some JSHint issues Mostly to reduce the scope of disabled warnings. - Allow es6 syntax - Disable specific lint rather than all where possible - Update jshint while we're at it --- .jshintrc | 2 +- package.json | 2 +- src/core/loader.js | 10 ++++++---- src/core/utility.js | 2 +- yarn.lock | 17 +++-------------- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.jshintrc b/.jshintrc index 403d008f..7c4993e1 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,6 @@ { "eqeqeq": true, - "esversion": 5, + "esversion": 6, "freeze": true, "futurehostile": true, "latedef": "nofunc", diff --git a/package.json b/package.json index 5e24afee..bcf1034c 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "grunt-browserify": "^5.0.0", "grunt-contrib-connect": "^1.0.2", "grunt-contrib-copy": "^1.0.0", - "grunt-contrib-jshint": "^1.0.0", + "grunt-contrib-jshint": "^1.1.0", "grunt-contrib-qunit": "^1.2.0", "grunt-contrib-uglify": "^2.0.0", "grunt-contrib-watch": "^1.0.0", diff --git a/src/core/loader.js b/src/core/loader.js index 4b9a7143..5096b373 100644 --- a/src/core/loader.js +++ b/src/core/loader.js @@ -257,14 +257,14 @@ module.exports = { isAsset = function(a) { return Crafty.asset(a) || null; }, - // jshint ignore:start + isSupportedAudio = function(f) { return Crafty.support.audio && Crafty.audio.supports( Utility.fileTypeOf( f ).type ); }, - // jshint ignore:end + isValidImage = function(f) { return -1 < Crafty.imageWhitelist.indexOf( @@ -332,7 +332,9 @@ module.exports = { current = (typeof current === "object") ? current : {'': current + ''}; - // jshint ignore:start + + // Disable (Don't make functions in a loop) warning + // jshint -W083 var files = Object.keys( current ).filter(function (key) { var fileUrl = getFilePath(type, current[key]); @@ -344,9 +346,9 @@ module.exports = { ) return shortURLOf( fileUrl ); }); + // jshint +W083 if ( files[0] ) obj = Crafty.audio.add(asset, files); - // jshint ignore:end //extract actual audio obj if audio creation was successfull if ( obj ) obj = obj.obj; diff --git a/src/core/utility.js b/src/core/utility.js index 81df3f6a..1700b1f8 100644 --- a/src/core/utility.js +++ b/src/core/utility.js @@ -6,7 +6,7 @@ exports.blobOf = function blobOf(URI) { XHR.open('GET', URI); - return new Promise(function (resolve, reject) { // jshint ignore:line + return new Promise(function (resolve, reject) { XHR.onload = function () { resolve( this.response ); }; diff --git a/yarn.lock b/yarn.lock index 60fd3d0f..ee735da9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1363,7 +1363,7 @@ find-up@^1.0.0: path-exists "^2.0.0" pinkie-promise "^2.0.0" -findup-sync@0.4.3, findup-sync@^0.4.3: +findup-sync@0.4.3: version "0.4.3" resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-0.4.3.tgz#40043929e7bc60adf0b7f4827c4c6e75a0deca12" dependencies: @@ -1664,7 +1664,7 @@ grunt-contrib-copy@^1.0.0: chalk "^1.1.1" file-sync-cmp "^0.1.0" -grunt-contrib-jshint@^1.0.0: +grunt-contrib-jshint@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/grunt-contrib-jshint/-/grunt-contrib-jshint-1.1.0.tgz#369d909b2593c40e8be79940b21340850c7939ac" dependencies: @@ -3162,18 +3162,7 @@ querystring@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" -qunitjs@^2.3.0: - version "2.3.1" - resolved "https://registry.yarnpkg.com/qunitjs/-/qunitjs-2.3.1.tgz#dedf1fc55c2a63c5faa3915c063a980c3facb716" - dependencies: - chokidar "1.6.1" - commander "2.9.0" - exists-stat "1.0.0" - findup-sync "^0.4.3" - js-reporters "1.2.0" - walk-sync "0.3.1" - -qunitjs@^2.4.1: +qunitjs@^2.3.0, qunitjs@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/qunitjs/-/qunitjs-2.4.1.tgz#88aba055a9e2ec3dbebfaad02471b2cb002c530b" dependencies: