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.
This commit is contained in:
Deathamns 2014-10-19 13:11:27 +02:00
parent 4278121f74
commit 0886f7e886
38 changed files with 112 additions and 38 deletions

20
src/.jshintrc Normal file
View File

@ -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
}
}

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global vAPI, uDom */ /* global µBlock, vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global µBlock, uDom */ /* global µBlock, vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, µBlock, YaMD5 */ /* global µBlock, vAPI, YaMD5 */
'use strict';
/******************************************************************************* /*******************************************************************************

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global µBlock */ /* global µBlock, vAPI */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,9 @@
Home: https://github.com/gorhill/uBlock 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 oneSecond = 1000;
var oneMinute = 60 * oneSecond; var oneMinute = 60 * oneSecond;
var oneHour = 60 * oneMinute; var oneHour = 60 * oneMinute;
var oneDay = 24 * oneHour; // var oneDay = 24 * oneHour;
/******************************************************************************/ /******************************************************************************/

View File

@ -19,18 +19,24 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, vAPI */ /* global vAPI */
'use strict';
/******************************************************************************/
// Injected into content pages // Injected into content pages
/******************************************************************************/
// because Safari // because Safari
if (location.protocol !== "http:" && location.protocol !== "https:") { if (location.protocol !== "http:" && location.protocol !== "https:") {
throw "uBlock> contentscript-end.js > Skipping page... " + location.protocol + location.host; throw "uBlock> contentscript-end.js > Skipping page... " + location.protocol + location.host;
} }
/******************************************************************************/
var messager = vAPI.messaging.channel('contentscript-end.js'); var messager = vAPI.messaging.channel('contentscript-end.js');
/******************************************************************************/
/******************************************************************************/ /******************************************************************************/
// ABP cosmetic filters // ABP cosmetic filters

View File

@ -20,7 +20,10 @@
*/ */
/* jshint multistr: true */ /* jshint multistr: true */
/* global chrome */ /* global vAPI */
'use strict';
/******************************************************************************/
// Injected into content pages // Injected into content pages

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, µBlock */ /* global vAPI, µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -21,6 +21,7 @@
/* jshint bitwise: false */ /* jshint bitwise: false */
/* global µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,6 +19,9 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
uDom.onLoad(function() { uDom.onLoad(function() {

View File

@ -19,6 +19,9 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
(function() { (function() {

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global CSS, chrome, vAPI */ /* global messager, CSS */
'use strict';
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
@ -107,7 +108,7 @@
}; };
} }
}(window)); }(this));
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/

View File

@ -19,6 +19,11 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global vAPI, uDom */
'use strict';
/******************************************************************************/
// Helper to deal with the i18n'ing of HTML files. // Helper to deal with the i18n'ing of HTML files.
uDom.onLoad(function() { uDom.onLoad(function() {

View File

@ -1,4 +1,6 @@
(function() { (function() {
'use strict';
document.body.style.display = "none"; document.body.style.display = "none";
document.addEventListener("DOMContentLoaded", function onDOMReady(e) { document.addEventListener("DOMContentLoaded", function onDOMReady(e) {
document.removeEventListener(e.type, onDOMReady, false); document.removeEventListener(e.type, onDOMReady, false);

View File

@ -21,6 +21,7 @@
/* jshint bitwise: false */ /* jshint bitwise: false */
/* global µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/
@ -60,16 +61,16 @@ var meltBucket = function(ldict, len, bucket) {
/******************************************************************************/ /******************************************************************************/
var melt = function(ldict) { // var melt = function(ldict) {
var buckets = ldict.dict; // var buckets = ldict.dict;
var bucket; // var bucket;
for ( var key in buckets ) { // for ( var key in buckets ) {
bucket = buckets[key]; // bucket = buckets[key];
if ( typeof bucket === 'string' ) { // if ( typeof bucket === 'string' ) {
buckets[key] = meltBucket(ldict, key.charCodeAt(0) & 0xFF, bucket); // buckets[key] = meltBucket(ldict, key.charCodeAt(0) & 0xFF, bucket);
} // }
} // }
}; // };
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global vAPI, µBlock, YaMD5 */ /* global µBlock, vAPI, YaMD5 */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -20,7 +20,8 @@
*/ */
/* jshint bitwise: false */ /* jshint bitwise: false */
/* global chrome, YaMD5, µBlock */ /* global µBlock, vAPI, YaMD5 */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,8 +19,9 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* jshint esnext: true, bitwise: false */ /* jshint bitwise: false */
/* global µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -20,7 +20,8 @@
*/ */
/* jshint bitwise: false */ /* jshint bitwise: false */
/* global µBlock */ /* global µBlock, vAPI */
'use strict';
/******************************************************************************* /*******************************************************************************

View File

@ -20,8 +20,8 @@
*/ */
/* global vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/
/******************************************************************************/ /******************************************************************************/
(function() { (function() {

View File

@ -19,6 +19,9 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* exported quickProfiler */
'use strict';
/******************************************************************************/ /******************************************************************************/
var quickProfiler = (function() { var quickProfiler = (function() {

View File

@ -20,6 +20,7 @@
*/ */
/* global vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -20,6 +20,7 @@
*/ */
/* global µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -21,6 +21,7 @@
/* jshint bitwise: false */ /* jshint bitwise: false */
/* global uDom, vAPI */ /* global uDom, vAPI */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, µBlock, punycode, publicSuffixList */ /* global µBlock, vAPI, punycode, publicSuffixList */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global µBlock */ /* global µBlock, vAPI */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global µBlock */ /* global µBlock, vAPI */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -20,6 +20,7 @@
*/ */
/* global µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -20,6 +20,10 @@
*/ */
/******************************************************************************/ /******************************************************************************/
/* exported uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
// It's just a silly, minimalist DOM framework: this allows me to not rely // It's just a silly, minimalist DOM framework: this allows me to not rely

View File

@ -20,6 +20,7 @@
*/ */
/* global µBlock, publicSuffixList */ /* 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. // This will inserted as a module in the µBlock object.
µBlock = typeof µBlock === "undefined" ? {} : µBlock; var µBlock = typeof µBlock === "undefined" ? {} : µBlock;
µBlock.URI = (function() { µBlock.URI = (function() {

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, µBlock */ /* global µBlock */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -1,5 +1,4 @@
// for non background pages // for non background pages
/* global chrome, Components, safari */
(function() { (function() {
'use strict'; 'use strict';

View File

@ -1,5 +1,4 @@
// only for background and other extension pages // only for background and other extension pages
/* global chrome, Components, BeforeLoadEvent */
(function() { (function() {
'use strict'; 'use strict';

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/

View File

@ -19,7 +19,8 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global chrome, µBlock */ /* global µBlock, vAPI */
'use strict';
/******************************************************************************/ /******************************************************************************/