From 0886f7e886f0625713c1584ba21938387d28f1dd Mon Sep 17 00:00:00 2001 From: Deathamns Date: Sun, 19 Oct 2014 13:11:27 +0200 Subject: [PATCH] Add .jshintrc, and use the "use strict" directive .jshintrc's otion-set is a personal choice, merely a suggestion. Beside that, it includes some common globals for specific browsers, so there's no need to set the globals in every .js file. In order to force strict coding, "use strict" directive was added into every .js file. --- src/.jshintrc | 20 ++++++++++++++++++++ src/js/1p-filters.js | 3 ++- src/js/3p-filters.js | 3 ++- src/js/about.js | 3 ++- src/js/asset-viewer.js | 3 ++- src/js/assets.js | 3 ++- src/js/async.js | 3 ++- src/js/background.js | 6 ++++-- src/js/contentscript-end.js | 10 ++++++++-- src/js/contentscript-start.js | 5 ++++- src/js/contextmenu.js | 3 ++- src/js/cosmetic-filtering.js | 1 + src/js/dashboard-common.js | 3 +++ src/js/dashboard.js | 3 +++ src/js/element-picker.js | 5 +++-- src/js/i18n.js | 5 +++++ src/js/js-loader.js | 2 ++ src/js/liquid-dict.js | 21 +++++++++++---------- src/js/messaging.js | 3 ++- src/js/mirrors.js | 3 ++- src/js/net-filtering.js | 3 ++- src/js/pagestore.js | 3 ++- src/js/popup.js | 2 +- src/js/profiler.js | 3 +++ src/js/settings.js | 1 + src/js/start.js | 1 + src/js/stats.js | 1 + src/js/storage.js | 3 ++- src/js/tab.js | 3 ++- src/js/traffic.js | 3 ++- src/js/ublock.js | 1 + src/js/udom.js | 4 ++++ src/js/uritools.js | 3 ++- src/js/utils.js | 3 ++- src/js/vapi-client.js | 1 - src/js/vapi-common.js | 1 - src/js/whitelist.js | 3 ++- src/js/xal.js | 3 ++- 38 files changed, 112 insertions(+), 38 deletions(-) create mode 100644 src/.jshintrc diff --git a/src/.jshintrc b/src/.jshintrc new file mode 100644 index 000000000..c927b55a1 --- /dev/null +++ b/src/.jshintrc @@ -0,0 +1,20 @@ +{ + "browser": true, + "devel": true, + "esnext": true, + "globalstrict": true, + "undef": true, + "unused": true, + "nonew": false, + "sub": true, + "boss": true, + "laxbreak": true, + "validthis": true, + "newcap": false, + "-W058": true, // suppress "Missing '()' invoking a constructor" message + "globals": { + "chrome": false, + "safari": false, + "Components": false // global variable in Firefox + } +} \ No newline at end of file diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index 4dae5e8f0..171620588 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, vAPI, uDom */ +/* global vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/3p-filters.js b/src/js/3p-filters.js index 9bd92c02f..cfe55e7ff 100644 --- a/src/js/3p-filters.js +++ b/src/js/3p-filters.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global vAPI, uDom */ +/* global µBlock, vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/about.js b/src/js/about.js index bd1b1804a..81fb1feea 100644 --- a/src/js/about.js +++ b/src/js/about.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock, uDom */ +/* global µBlock, vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/asset-viewer.js b/src/js/asset-viewer.js index 2167ac83b..fb6c80633 100644 --- a/src/js/asset-viewer.js +++ b/src/js/asset-viewer.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, vAPI, uDom */ +/* global vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/assets.js b/src/js/assets.js index 288ffc23c..655add43b 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock, YaMD5 */ +/* global µBlock, vAPI, YaMD5 */ +'use strict'; /******************************************************************************* diff --git a/src/js/async.js b/src/js/async.js index 6e64cc39a..21f8df8f4 100644 --- a/src/js/async.js +++ b/src/js/async.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock */ +/* global µBlock, vAPI */ +'use strict'; /******************************************************************************/ diff --git a/src/js/background.js b/src/js/background.js index b47cc026b..54a465b53 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -19,7 +19,9 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome */ +/* global vAPI */ +/* exported µBlock */ +'use strict'; /******************************************************************************/ @@ -30,7 +32,7 @@ var µBlock = (function() { var oneSecond = 1000; var oneMinute = 60 * oneSecond; var oneHour = 60 * oneMinute; -var oneDay = 24 * oneHour; +// var oneDay = 24 * oneHour; /******************************************************************************/ diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 33efb2e4c..351160070 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -19,18 +19,24 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, vAPI */ +/* global vAPI */ +'use strict'; + +/******************************************************************************/ // Injected into content pages +/******************************************************************************/ + // because Safari if (location.protocol !== "http:" && location.protocol !== "https:") { throw "uBlock> contentscript-end.js > Skipping page... " + location.protocol + location.host; } +/******************************************************************************/ + var messager = vAPI.messaging.channel('contentscript-end.js'); -/******************************************************************************/ /******************************************************************************/ // ABP cosmetic filters diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 39c592650..19e54ca7b 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -20,7 +20,10 @@ */ /* jshint multistr: true */ -/* global chrome */ +/* global vAPI */ +'use strict'; + +/******************************************************************************/ // Injected into content pages diff --git a/src/js/contextmenu.js b/src/js/contextmenu.js index 519cfc5a4..a973fb897 100644 --- a/src/js/contextmenu.js +++ b/src/js/contextmenu.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock */ +/* global vAPI, µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 1794bbe19..35324c9c8 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -21,6 +21,7 @@ /* jshint bitwise: false */ /* global µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/dashboard-common.js b/src/js/dashboard-common.js index 858501221..2563ee562 100644 --- a/src/js/dashboard-common.js +++ b/src/js/dashboard-common.js @@ -19,6 +19,9 @@ Home: https://github.com/gorhill/uBlock */ +/* global uDom */ +'use strict'; + /******************************************************************************/ uDom.onLoad(function() { diff --git a/src/js/dashboard.js b/src/js/dashboard.js index b1e7aa496..8040d92d4 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -19,6 +19,9 @@ Home: https://github.com/gorhill/uBlock */ +/* global uDom */ +'use strict'; + /******************************************************************************/ (function() { diff --git a/src/js/element-picker.js b/src/js/element-picker.js index c9bd620d1..7103aabb0 100644 --- a/src/js/element-picker.js +++ b/src/js/element-picker.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global CSS, chrome, vAPI */ +/* global messager, CSS */ +'use strict'; /******************************************************************************/ /******************************************************************************/ @@ -107,7 +108,7 @@ }; } -}(window)); +}(this)); /******************************************************************************/ /******************************************************************************/ diff --git a/src/js/i18n.js b/src/js/i18n.js index 11cc26f8d..ce05041e2 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -19,6 +19,11 @@ Home: https://github.com/gorhill/uBlock */ +/* global vAPI, uDom */ +'use strict'; + +/******************************************************************************/ + // Helper to deal with the i18n'ing of HTML files. uDom.onLoad(function() { diff --git a/src/js/js-loader.js b/src/js/js-loader.js index 326801c79..cd60baa47 100644 --- a/src/js/js-loader.js +++ b/src/js/js-loader.js @@ -1,4 +1,6 @@ (function() { + 'use strict'; + document.body.style.display = "none"; document.addEventListener("DOMContentLoaded", function onDOMReady(e) { document.removeEventListener(e.type, onDOMReady, false); diff --git a/src/js/liquid-dict.js b/src/js/liquid-dict.js index 08744d7e6..e17f019b4 100644 --- a/src/js/liquid-dict.js +++ b/src/js/liquid-dict.js @@ -21,6 +21,7 @@ /* jshint bitwise: false */ /* global µBlock */ +'use strict'; /******************************************************************************/ @@ -60,16 +61,16 @@ var meltBucket = function(ldict, len, bucket) { /******************************************************************************/ -var melt = function(ldict) { - var buckets = ldict.dict; - var bucket; - for ( var key in buckets ) { - bucket = buckets[key]; - if ( typeof bucket === 'string' ) { - buckets[key] = meltBucket(ldict, key.charCodeAt(0) & 0xFF, bucket); - } - } -}; +// var melt = function(ldict) { +// var buckets = ldict.dict; +// var bucket; +// for ( var key in buckets ) { +// bucket = buckets[key]; +// if ( typeof bucket === 'string' ) { +// buckets[key] = meltBucket(ldict, key.charCodeAt(0) & 0xFF, bucket); +// } +// } +// }; /******************************************************************************/ diff --git a/src/js/messaging.js b/src/js/messaging.js index 87b549dd3..e8942d8c5 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global vAPI, µBlock, YaMD5 */ +/* global µBlock, vAPI, YaMD5 */ +'use strict'; /******************************************************************************/ diff --git a/src/js/mirrors.js b/src/js/mirrors.js index 14f096ccf..0e61cf58e 100644 --- a/src/js/mirrors.js +++ b/src/js/mirrors.js @@ -20,7 +20,8 @@ */ /* jshint bitwise: false */ -/* global chrome, YaMD5, µBlock */ +/* global µBlock, vAPI, YaMD5 */ +'use strict'; /******************************************************************************/ diff --git a/src/js/net-filtering.js b/src/js/net-filtering.js index 70d0d58c1..82338cc8f 100644 --- a/src/js/net-filtering.js +++ b/src/js/net-filtering.js @@ -19,8 +19,9 @@ Home: https://github.com/gorhill/uBlock */ -/* jshint esnext: true, bitwise: false */ +/* jshint bitwise: false */ /* global µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/pagestore.js b/src/js/pagestore.js index e74066273..26746b683 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -20,7 +20,8 @@ */ /* jshint bitwise: false */ -/* global µBlock */ +/* global µBlock, vAPI */ +'use strict'; /******************************************************************************* diff --git a/src/js/popup.js b/src/js/popup.js index 08c605d66..f5dec3109 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -20,8 +20,8 @@ */ /* global vAPI, uDom */ +'use strict'; -/******************************************************************************/ /******************************************************************************/ (function() { diff --git a/src/js/profiler.js b/src/js/profiler.js index e7947565c..27fc0ed80 100644 --- a/src/js/profiler.js +++ b/src/js/profiler.js @@ -19,6 +19,9 @@ Home: https://github.com/gorhill/uBlock */ +/* exported quickProfiler */ +'use strict'; + /******************************************************************************/ var quickProfiler = (function() { diff --git a/src/js/settings.js b/src/js/settings.js index 023e3581e..acd162508 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -20,6 +20,7 @@ */ /* global vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/start.js b/src/js/start.js index 826303b75..d2df18a53 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -20,6 +20,7 @@ */ /* global µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/stats.js b/src/js/stats.js index 5d4eb47b6..103be33e9 100644 --- a/src/js/stats.js +++ b/src/js/stats.js @@ -21,6 +21,7 @@ /* jshint bitwise: false */ /* global uDom, vAPI */ +'use strict'; /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index 196e03782..ec3e5433f 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock, punycode, publicSuffixList */ +/* global µBlock, vAPI, punycode, publicSuffixList */ +'use strict'; /******************************************************************************/ diff --git a/src/js/tab.js b/src/js/tab.js index 91bfb088a..08fa4bcaf 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock */ +/* global µBlock, vAPI */ +'use strict'; /******************************************************************************/ diff --git a/src/js/traffic.js b/src/js/traffic.js index 5ec2691b8..8d1d70ef7 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock */ +/* global µBlock, vAPI */ +'use strict'; /******************************************************************************/ diff --git a/src/js/ublock.js b/src/js/ublock.js index c9019c748..56fc6adb7 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -20,6 +20,7 @@ */ /* global µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/udom.js b/src/js/udom.js index 4e9925765..8b59e4208 100644 --- a/src/js/udom.js +++ b/src/js/udom.js @@ -20,6 +20,10 @@ */ /******************************************************************************/ + +/* exported uDom */ +'use strict'; + /******************************************************************************/ // It's just a silly, minimalist DOM framework: this allows me to not rely diff --git a/src/js/uritools.js b/src/js/uritools.js index 7e5ccb414..c2034104e 100644 --- a/src/js/uritools.js +++ b/src/js/uritools.js @@ -20,6 +20,7 @@ */ /* global µBlock, publicSuffixList */ +'use strict'; /******************************************************************************* @@ -33,7 +34,7 @@ Naming convention from https://en.wikipedia.org/wiki/URI_scheme#Examples // This will inserted as a module in the µBlock object. -µBlock = typeof µBlock === "undefined" ? {} : µBlock; +var µBlock = typeof µBlock === "undefined" ? {} : µBlock; µBlock.URI = (function() { diff --git a/src/js/utils.js b/src/js/utils.js index 96bfc0980..d6aadb1dc 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock */ +/* global µBlock */ +'use strict'; /******************************************************************************/ diff --git a/src/js/vapi-client.js b/src/js/vapi-client.js index 76058e169..d97d35f45 100644 --- a/src/js/vapi-client.js +++ b/src/js/vapi-client.js @@ -1,5 +1,4 @@ // for non background pages -/* global chrome, Components, safari */ (function() { 'use strict'; diff --git a/src/js/vapi-common.js b/src/js/vapi-common.js index 2997a111c..d70c4497a 100644 --- a/src/js/vapi-common.js +++ b/src/js/vapi-common.js @@ -1,5 +1,4 @@ // only for background and other extension pages -/* global chrome, Components, BeforeLoadEvent */ (function() { 'use strict'; diff --git a/src/js/whitelist.js b/src/js/whitelist.js index b23b261ce..e6dcecbd5 100644 --- a/src/js/whitelist.js +++ b/src/js/whitelist.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, vAPI, uDom */ +/* global vAPI, uDom */ +'use strict'; /******************************************************************************/ diff --git a/src/js/xal.js b/src/js/xal.js index db474ce6a..be9e017d6 100644 --- a/src/js/xal.js +++ b/src/js/xal.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock */ +/* global µBlock, vAPI */ +'use strict'; /******************************************************************************/