From 4edfae4b94e5bc8109bc4eb50ba0f7aba6dda0f4 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 21 Jan 2015 08:59:23 -0500 Subject: [PATCH] code review: jshint'ed --- platform/chromium/vapi-background.js | 10 ++++------ platform/firefox/vapi-background.js | 7 ++++--- platform/safari/vapi-background.js | 4 ++-- src/js/background.js | 1 + src/js/pagestore.js | 1 - src/js/static-net-filtering.js | 11 ++++++----- src/js/traffic.js | 1 - 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 9af049fdf..a8f260f68 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -95,7 +95,7 @@ vAPI.tabs.get = function(tabId, callback) { var onTabReady = function(tab) { // https://code.google.com/p/chromium/issues/detail?id=410868#c8 if ( chrome.runtime.lastError ) { - ; + /* noop */ } // Caller must be prepared to deal with nil tab value callback(tab); @@ -110,7 +110,7 @@ vAPI.tabs.get = function(tabId, callback) { var onTabReceived = function(tabs) { // https://code.google.com/p/chromium/issues/detail?id=410868#c8 if ( chrome.runtime.lastError ) { - ; + /* noop */ } callback(tabs[0]); }; @@ -149,10 +149,8 @@ vAPI.tabs.open = function(details) { }; if ( details.tabId ) { - details.tabId = parseInt(tabId, 10); - // update doesn't accept index, must use move - chrome.tabs.update(details.tabId, _details, function(tab) { + chrome.tabs.update(parseInt(details.tabId, 10), _details, function(tab) { // if the tab doesn't exist if ( vAPI.lastError() ) { chrome.tabs.create(_details); @@ -219,7 +217,7 @@ vAPI.tabs.remove = function(tabId) { /******************************************************************************/ -vAPI.tabs.reload = function(tabId, flags) { +vAPI.tabs.reload = function(tabId /*, flags*/) { if ( typeof tabId === 'string' ) { tabId = parseInt(tabId, 10); } diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 33b191627..2d8d2f270 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -19,7 +19,8 @@ Home: https://github.com/gorhill/uBlock */ -/* global punycode */ +/* jshint esnext: true, bitwise: false */ +/* global self, Components, punycode */ // For background page @@ -143,7 +144,7 @@ vAPI.storage = { sqlWhere: function(col, params) { if ( params > 0 ) { - params = Array(params + 1).join('?, ').slice(0, -2); + params = new Array(params + 1).join('?, ').slice(0, -2); return ' WHERE ' + col + ' IN (' + params + ')'; } @@ -1000,7 +1001,7 @@ var httpObserver = { // Probably isn't the best method to identify the source tab if ( tabURI.spec !== lastRequest.openerURL ) { - continue + continue; } sourceTabId = vAPI.tabs.getTabId(tab); diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index f96761fd0..10fdbf31f 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock, SafariBrowserTab */ +/* global self, safari, SafariBrowserTab, µBlock */ // For background page @@ -360,7 +360,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) { } if ( details.file ) { - var xhr = new XMLHttpRequest; + var xhr = new XMLHttpRequest(); xhr.overrideMimeType('application/x-javascript;charset=utf-8'); xhr.open('GET', details.file, false); xhr.send(); diff --git a/src/js/background.js b/src/js/background.js index 5f09784a5..b47fe0af0 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -19,6 +19,7 @@ Home: https://github.com/gorhill/uBlock */ +/* global vAPI */ /* exported µBlock */ /******************************************************************************/ diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 2b94bc3ed..d91c81b27 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -261,7 +261,6 @@ NetFilteringResultCacheEntry.factory = function(result, type) { /******************************************************************************/ // To mitigate memory churning -var uidGenerator = 1; var netFilteringCacheJunkyard = []; var netFilteringCacheJunkyardMax = 10; diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 1e81d4a1a..3e106a94a 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -68,7 +68,7 @@ var typeNameToTypeValue = { 'inline-script': 14 << 4, 'popup': 15 << 4 }; -var typeOtherToTypeValue = typeNameToTypeValue['other']; +var typeOtherToTypeValue = typeNameToTypeValue.other; const BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty; const BlockAnyType = BlockAction | AnyType; @@ -1756,9 +1756,10 @@ FilterContainer.prototype.matchStringExactType = function(context, requestURL, r pageHostname = context.pageHostname || ''; // Be prepared to support unknown types - var type = typeNameToTypeValue[requestType] || typeOtherToTypeValue; - var categories = this.categories; + var bf = false; var bucket; + var categories = this.categories; + var type = typeNameToTypeValue[requestType] || typeOtherToTypeValue; // Tokenize only once this.tokenize(url); @@ -1779,7 +1780,6 @@ FilterContainer.prototype.matchStringExactType = function(context, requestURL, r } // Test against block filters - bf = false; if ( bucket = categories[this.makeCategoryKey(BlockAnyParty | type)] ) { bf = this.matchTokens(bucket, url); } @@ -1855,12 +1855,13 @@ FilterContainer.prototype.matchString = function(context) { // This will be used by hostname-based filters pageHostname = context.pageHostname || ''; + var bf, bucket; var categories = this.categories; - var bucket; // Tokenize only once this.tokenize(url); + // https://github.com/gorhill/uBlock/issues/139 // Test against important block filters. // The purpose of the `important` option is to reverse the order of diff --git a/src/js/traffic.js b/src/js/traffic.js index 0bd3182da..7e61e3b5b 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -299,7 +299,6 @@ var headerValue = function(headers, name) { /******************************************************************************/ var headerStartsWith = function(headers, prefix) { - var prefixLen = prefix.length; var i = headers.length; while ( i-- ) { if ( headers[i].name.toLowerCase().lastIndexOf(prefix, 0) === 0 ) {