From 088617d834f4d418870f654b90130c0a5492d8a2 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Thu, 24 Apr 2014 16:39:27 +1200 Subject: [PATCH 1/4] Fix a few JS warnings that pop into the console --- data/aggregate.js | 1 + data/svgdataset.js | 6 ++++-- data/ui.js | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/aggregate.js b/data/aggregate.js index ca5646e..69ebd2d 100644 --- a/data/aggregate.js +++ b/data/aggregate.js @@ -286,6 +286,7 @@ function GraphEdge(source, target, connection) { if (connection) { this.cookieCount = connection.cookie ? 1 : 0; } + return this; // console.log('edge: %s', this.name); } GraphEdge.prototype.lastAccess = function () { diff --git a/data/svgdataset.js b/data/svgdataset.js index f607670..2a4d188 100644 --- a/data/svgdataset.js +++ b/data/svgdataset.js @@ -26,9 +26,11 @@ function svgdataset(elem) { return value; } } else { - elem.setAttribute(dataKeyToAttr(key), JSON.stringify(value)); + var s = JSON.stringify(value); + elem.setAttribute(dataKeyToAttr(key), s); + return s; } - } + }; // Create read-only shortcuts for convenience Array.prototype.forEach.call(elem.attributes, function (attr) { if (attr.name.startsWith('data-')) { diff --git a/data/ui.js b/data/ui.js index ade3db5..fb73f0f 100644 --- a/data/ui.js +++ b/data/ui.js @@ -182,6 +182,7 @@ global.getZoom = function getZoom(canvas) { } catch (e) { console.log('error in getZoom, called with %o instead of an element'); console.log('Caller: %o', caller); + return null; } } From de3d0cfd54de1bd27459650ef5f63b7d0678db91 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Fri, 25 Apr 2014 11:48:33 +1200 Subject: [PATCH 2/4] Fix the least controversial jshint warnings To install jshint, simply `npm install jshint` from the root directory of the project. Then run like it like this: node_modules/.bin/jshint data/*.js --- .gitignore | 1 + data/aggregate.js | 21 ++++++++++---------- data/dialog.js | 3 ++- data/graph.js | 18 +++++++++-------- data/infobar.js | 4 ++-- data/lightbeam.js | 13 ++++++------ data/list.js | 15 +++++++------- data/parseuri.js | 2 +- data/svgdataset.js | 2 +- data/ui.js | 44 +++++++++++++++++++++-------------------- lib/connection.js | 16 ++++++++------- lib/main.js | 4 +++- lib/persist.js | 10 ++++++---- lib/shared/menuitems.js | 18 ++++++++++------- lib/shared/policy.js | 2 ++ lib/shared/unload+.js | 4 +++- lib/tab/events.js | 2 ++ lib/tab/utils.js | 5 +++-- lib/ui.js | 15 ++++++++------ 19 files changed, 114 insertions(+), 85 deletions(-) diff --git a/.gitignore b/.gitignore index 76f29e0..11055fc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ data/deployment.json *.xpi exported_graphs *.swp +/node_modules diff --git a/data/aggregate.js b/data/aggregate.js index 69ebd2d..8e1e1f5 100644 --- a/data/aggregate.js +++ b/data/aggregate.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ // Graph Visualization // Visualization of tracking data interconnections @@ -50,7 +51,7 @@ aggregate.getBlockedDomains = function () { return Object.keys(userSettings).filter(function (domain) { return userSettings[domain] == 'block'; }); -} +}; aggregate.getAllNodes = function () { var blockedDomains = aggregate.getBlockedDomains(); @@ -63,7 +64,7 @@ aggregate.getAllNodes = function () { name: domain }; })); -} +}; aggregate.getConnectionCount = function (node) { if (node.nodeType === 'blocked') @@ -71,11 +72,11 @@ aggregate.getConnectionCount = function (node) { let connections = Object.keys(aggregate.nodeForKey(node.name)).length; return connections - 1 > 0 ? connections - 1 : 0; -} +}; aggregate.nodeForKey = function (key) { var result = {}; - var linkedNodes = new Array(); + var linkedNodes = []; if (aggregate.nodemap[key]) { linkedNodes = aggregate.nodemap[key].linkedFrom.concat(aggregate.nodemap[key].linkedTo); @@ -120,7 +121,7 @@ aggregate.connectionAsObject = function (conn) { } return conn; -} +}; // Pass the list of connections to build the graph structure to pass to d3 for // visualizations. @@ -167,7 +168,7 @@ const CACHEABLE = 13; // of false positives. aggregate.isDomainVisited = function isDomainVisited(domain) { return aggregate.recentSites.length && (aggregate.recentSites.indexOf(domain) > -1); -} +}; function onConnection(conn) { @@ -236,7 +237,7 @@ function onConnection(conn) { aggregate.trackerCount++; } // console.log('new target: %s, now %s nodes', targetnode.name, aggregate.nodes.length); - updated = true + updated = true; } // Create edge objects. Could probably do this lazily just for the graph view if (aggregate.edgemap[connection.source + '->' + connection.target]) { @@ -291,13 +292,13 @@ function GraphEdge(source, target, connection) { } GraphEdge.prototype.lastAccess = function () { return (this.source.lastAccess > this.target.lastAccess) ? this.source.lastAccess : this.target.lastAccess; -} +}; GraphEdge.prototype.firstAccess = function () { return (this.source.firstAccess < this.target.firstAccess) ? this.source.firstAccess : this.target.firstAccess; -} +}; GraphEdge.prototype.update = function (connection) { this.cookieCount = connection.cookie ? this.cookieCount + 1 : this.cookieCount; -} +}; // A graph node represents one end of a connection, either a target or a source // Where a connection is a point in time with a timestamp, a graph node has a time range diff --git a/data/dialog.js b/data/dialog.js index f3186f7..43fd02e 100644 --- a/data/dialog.js +++ b/data/dialog.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ /* Dialog / Popup ===================================== */ // dialog names (used as dialog identifiers) @@ -118,7 +119,7 @@ function addDialogEventHandlers(modal, options, callback) { modal.close(); callback(false); } - } + }; document.addEventListener("keydown", keyDownHandler); modal.onClose(function () { diff --git a/data/graph.js b/data/graph.js index 7172a25..6edccb4 100644 --- a/data/graph.js +++ b/data/graph.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ // Graph Visualization (one of 3 views: graph, clock, and list). This is way // too heavyweight for mobile right now. @@ -70,7 +71,7 @@ function onInit() { vizcanvas.setAttribute('viewBox', [0, 0, width, height].join(' ')); // console.log('graph::onInit end'); document.querySelector(".filter-display").classList.remove("hidden"); -}; +} function onRemove() { // var startTime = Date.now(); @@ -81,7 +82,7 @@ function onRemove() { resetCanvas(); document.querySelector(".filter-display").classList.add("hidden"); // console.log('it took %s ms to remove graph view', Date.now() - startTime); -}; +} function onReset() { onRemove(); @@ -161,23 +162,24 @@ function charge(d) { } function colourHighlightNodes(highlight) { + var i; var watchedSites = document.querySelectorAll(".watched"); var blockedSites = document.querySelectorAll(".blocked"); if (highlight.watched) { - for (var i = 0; i < watchedSites.length; i++) { + for (i = 0; i < watchedSites.length; i++) { watchedSites[i].classList.add("watchedSites"); } } else { - for (var i = 0; i < watchedSites.length; i++) { + for (i = 0; i < watchedSites.length; i++) { watchedSites[i].classList.remove("watchedSites"); } } if (highlight.blocked) { - for (var i = 0; i < blockedSites.length; i++) { + for (i = 0; i < blockedSites.length; i++) { blockedSites[i].classList.add("blockedSites"); } } else { - for (var i = 0; i < blockedSites.length; i++) { + for (i = 0; i < blockedSites.length; i++) { blockedSites[i].classList.remove("blockedSites"); } } @@ -243,7 +245,7 @@ function initGraph() { }); nodes.each(function (d, i) { // `this` is the DOM node - this.setAttribute('transform', 'translate(' + d.x + ',' + d.y + ') scale(' + (1 + .05 * d.weight) + ')'); + this.setAttribute('transform', 'translate(' + d.x + ',' + d.y + ') scale(' + (1 + 0.05 * d.weight) + ')'); this.setAttribute('data-timestamp', d.lastAccess.toISOString()); if (d.nodeType === 'site' || d.nodeType === 'both') { this.classList.add('visitedYes'); @@ -317,7 +319,7 @@ function addCircle(selection) { .append('circle') .attr('cx', 0) .attr('cy', 0) - .attr('r', graphNodeRadius["graph"]) + .attr('r', graphNodeRadius.graph) .classed('site', true); } diff --git a/data/infobar.js b/data/infobar.js index 4cf99b6..d8d66f9 100644 --- a/data/infobar.js +++ b/data/infobar.js @@ -48,7 +48,7 @@ global.initMap = function initMap(mapcanvas, mapDocument) { if (currentRequest === info.host) { callback((request.status === 200) ? JSON.parse(request.responseText) : false); } - } + }; request.send(null); } @@ -271,7 +271,7 @@ global.initMap = function initMap(mapcanvas, mapDocument) { }, false); -} +}; /* Info Panel Tabs ======================================== */ diff --git a/data/lightbeam.js b/data/lightbeam.js index 554f0cb..0ffe675 100644 --- a/data/lightbeam.js +++ b/data/lightbeam.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ (function (global) { 'use strict'; @@ -66,7 +67,7 @@ global.elem = function elem(name, attributes, children) { } }); } - } catch (e) { + } catch (err) { console.log('attributes: not what we think they are: %o', attributes); } if (children) { @@ -113,7 +114,7 @@ global.switchVisualization = function switchVisualization(name) { defaultVisualization: name }); // console.log('it took %s ms to switch visualizations', Date.now() - startTime); -} +}; function resetAdditionalUI() { // toggle off info panel @@ -150,7 +151,7 @@ global.startSharing = function startSharing(askForConfirmation, callback) { } else { callback(true); } -} +}; /**************************************** * Format date string @@ -164,7 +165,7 @@ global.formattedDate = function formattedDate(date, format) { formatted = dayInWeek + ", " + formatted + " " + ((d.getHours() == 12) ? 12 : (d.getHours() % 12)) + ':' + d.toLocaleFormat('%M') + ['AM', 'PM'][Math.floor(d.getHours() / 12)]; } return formatted; -} +}; global.singularOrPluralNoun = function singularOrPluralNoun(num, str) { @@ -172,7 +173,7 @@ global.singularOrPluralNoun = function singularOrPluralNoun(num, str) { num = parseFloat(num); } return (num !== 1) ? str + "s" : str; -} +}; /**************************************** * update Stats Bar @@ -185,6 +186,6 @@ global.updateStatsBar = function updateStatsBar() { document.querySelector(".top-bar .date-gathered").textContent = dateSince; document.querySelector(".top-bar .third-party-sites").textContent = aggregate.trackerCount + " " + singularOrPluralNoun(aggregate.trackerCount, "THIRD PARTY SITE"); document.querySelector(".top-bar .first-party-sites").textContent = aggregate.siteCount + " " + singularOrPluralNoun(aggregate.siteCount, "SITE"); -} +}; })(this); diff --git a/data/list.js b/data/list.js index 69e3852..ef84323 100644 --- a/data/list.js +++ b/data/list.js @@ -1,10 +1,10 @@ -'use strict'; - +/* jshint moz: true */ // List Visualization // Display data in tabular format (function (visualizations, global) { +"use strict"; var list = new Emitter(); var breadcrumbStack = []; @@ -482,7 +482,7 @@ function sortTableOnColumn(table, n) { tbody.appendChild(preFrag); tbody.appendChild(frag); - } + }; } function resetCanvas() { @@ -511,7 +511,7 @@ function getSelectedRows() { // returns selected rows as an Array return getAllRows().filter(function (item) { return item.querySelector('.selected-row:checked'); - }) + }); } // Event handlers @@ -539,16 +539,17 @@ function setUserSetting(row, pref) { // selectAllRows should only select VISIBLE rows function selectAllRows(flag) { + var i; // apply flag to ALL rows first var rows = document.querySelectorAll(".body-table tr"); - for (var i = 0; i < rows.length; i++) { + for (i = 0; i < rows.length; i++) { rows[i].querySelector(".selected-row").checked = flag; highlightRow(rows[i], flag); } // and then exclude all the hidden rows if (document.querySelector(".hide-hidden-rows")) { var hiddenRows = document.querySelectorAll(".list-table .body-table tr[data-pref=hide]"); - for (var i = 0; i < hiddenRows.length; i++) { + for (i = 0; i < hiddenRows.length; i++) { hiddenRows[i].querySelector(".selected-row").checked = false; // makes sure the hidden rows are always unchecked highlightRow(hiddenRows[i], false); } @@ -645,7 +646,7 @@ function initializeHandlers() { }); showFilteredTable(lastFilter); selected = getAllRows().filter(function (row) { - return wereSelected.indexOf(row.dataset.name) > -1 + return wereSelected.indexOf(row.dataset.name) > -1; }) .map(function (rowToSelect) { rowToSelect.querySelector("[type=checkbox]").checked = true; diff --git a/data/parseuri.js b/data/parseuri.js index 1b82b6d..f04257f 100755 --- a/data/parseuri.js +++ b/data/parseuri.js @@ -16,7 +16,7 @@ function parseUri(str) { }); return uri; -}; +} parseUri.options = { strictMode: false, diff --git a/data/svgdataset.js b/data/svgdataset.js index 2a4d188..5fdd4e2 100644 --- a/data/svgdataset.js +++ b/data/svgdataset.js @@ -20,7 +20,7 @@ function svgdataset(elem) { // act as getter value = elem.getAttribute(dataKeyToAttr(key)); try { - get + get; return JSON.parse(value); } catch (e) { return value; diff --git a/data/ui.js b/data/ui.js index fb73f0f..cadff8f 100644 --- a/data/ui.js +++ b/data/ui.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ (function (global) { // Bunch of utilities related to UI elements. const graphNodeRadius = { @@ -10,7 +11,7 @@ global.graphNodeRadius = graphNodeRadius; /* Convert a NodeList to Array */ global.toArray = function toArray(nl) { return Array.prototype.slice.call(nl, 0); -} +}; /************************************************** * For accessibility: @@ -94,7 +95,7 @@ global.confirmStartSharing = function confirmStartSharing(askForConfirmation, el elmClicked.checked = false; } }); -} +}; global.confirmStopSharing = function confirmStopSharing(elmClicked) { stopSharingDialog(function (confirmed) { @@ -107,7 +108,7 @@ global.confirmStopSharing = function confirmStopSharing(elmClicked) { elmClicked.checked = true; } }); -} +}; function toggleBtnOnEffect(toggleBtn) { toggleBtn.querySelector(".toggle-btn-innner").classList.add("checked"); @@ -135,7 +136,7 @@ function downloadAsJson(data, defaultFilename) { a.target = '_blank'; document.body.appendChild(a); a.click(); - } + }; reader.readAsDataURL(file); } @@ -184,12 +185,12 @@ global.getZoom = function getZoom(canvas) { console.log('Caller: %o', caller); return null; } -} +}; global.setZoom = function setZoom(box, canvas) { // TODO: code cleanup if both cases use basically the same code canvas.setAttribute('viewBox', [box.x, box.y, box.w, box.h].join(' ')); -} +}; /* Scroll over visualization to zoom in/out ========================= */ @@ -244,15 +245,16 @@ function checkWithinZoomLimit(targetSvg, zoomType, zoomLimit) { // Check to see if the viewBox of the targeting svg is within the limit we define // if yes, zoom function zoomWithinLimit(scrollDist, targetSvg, zoomInLimit, zoomOutLimit) { + var i; if (scrollDist >= 1) { // scroll up to zoom out - for (var i = 1; i <= scrollDist; i++) { + for (i = 1; i <= scrollDist; i++) { if (checkWithinZoomLimit(targetSvg, "out", zoomOutLimit)) { svgZooming(targetSvg, (1 / svgZoomingRatio)); } } } if (scrollDist <= -1) { // scroll down to zoom in - for (var i = scrollDist; i <= -1; i++) { + for (i = scrollDist; i <= -1; i++) { if (checkWithinZoomLimit(targetSvg, "in", zoomInLimit)) { svgZooming(targetSvg, svgZoomingRatio); } @@ -341,13 +343,13 @@ global.toggleLegendSection = function toggleLegendSection(eventTarget, legendElm elmToToggle.classList.add("hidden"); eventTarget.textContent = "Show"; } -} +}; global.toggleVizElements = function toggleVizElements(elements, classToggle) { toArray(elements).forEach(function (elm) { elm.classList.toggle(classToggle); }); -} +}; @@ -361,7 +363,7 @@ global.selectedNodeEffect = function selectedNodeEffect(name) { if (g.currentVisualization.name == "list") { resetHighlightedRow(); } -} +}; global.connectedNodeEffect = function connectedNodeEffect(name) { // console.log(name); @@ -380,7 +382,7 @@ global.connectedNodeEffect = function connectedNodeEffect(name) { } } -} +}; // for Graph & Clock global.addGlow = function addGlow(name, type) { @@ -398,7 +400,7 @@ global.addGlow = function addGlow(name, type) { .classed(type, true); }); -} +}; global.calculateGlowSize = function calculateGlowSize(gNode, viz) { var glowProps = {}; @@ -416,7 +418,7 @@ global.calculateGlowSize = function calculateGlowSize(gNode, viz) { glowProps.cy = siteNode.getAttribute("cy") || 0; return glowProps; -} +}; // for Graph global.resetAllGlow = function resetAllGlow(type) { @@ -434,7 +436,7 @@ global.resetAllGlow = function resetAllGlow(type) { connectedGlow.parentNode.removeChild(connectedGlow); } } -} +}; // for List global.resetHighlightedRow = function resetHighlightedRow() { @@ -442,7 +444,7 @@ global.resetHighlightedRow = function resetHighlightedRow() { if (preHighlighted) { preHighlighted.classList.remove("selected-connected-row"); } -} +}; /************************************************** * Singular / Plural Noun @@ -452,12 +454,12 @@ global.singularOrPluralNoun = function singularOrPluralNoun(num, str) { num = parseFloat(num); } return (num > 1) ? str + "s" : str; -} +}; function updateUIFromPrefs(event) { - if ("contributeData" in event && event["contributeData"]) { + if ("contributeData" in event && event.contributeData) { var toggleBtn = document.querySelector(".share-btn"); - if (event["contributeData"]) { + if (event.contributeData) { toggleBtn.querySelector("input").checked = true; toggleBtnOnEffect(toggleBtn); } else { @@ -466,7 +468,7 @@ function updateUIFromPrefs(event) { } } if ("defaultVisualization" in event) { - global.currentVisualization = visualizations[event["defaultVisualization"]]; + global.currentVisualization = visualizations[event.defaultVisualization]; if (global.currentVisualization) { console.log("Got viz"); } else { @@ -475,7 +477,7 @@ function updateUIFromPrefs(event) { } if ("defaultFilter" in event) { - aggregate.currentFilter = event["defaultFilter"]; + aggregate.currentFilter = event.defaultFilter; document.querySelector('a[data-value=' + aggregate.currentFilter + ']') .dataset.selected = true; document.querySelector(".filter-display header").textContent = diff --git a/lib/connection.js b/lib/connection.js index b685080..66ea6ad 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ // Connection object. This module may try to do too many things. // // Convert an HTTP request (channel) to a loggable, visualizable connection @@ -45,7 +46,7 @@ exports.getAllConnections = function getAllConnections() { console.log("got", connBatch.length, "buffered connections", ss.storage.connections.length, "persisted connections"); return ss.storage.connections.concat(connBatch); -} +}; function excludePrivateConnections(connections) { return connections.filter(function (connection) { @@ -80,7 +81,7 @@ function getDomain(host) { Connection.getDomain = getDomain; // make it part of what we export Connection.reset = function () { connBatch.length = 0; -} +}; // Get subdomain (e.g., foo from foo.example.com) function getSubdomain(host) { @@ -88,14 +89,14 @@ function getSubdomain(host) { return host.slice(0, host.length - domain.length); } -function Connection() {}; +function Connection() {} // subject comes from events.on("http-on-modify-request"); Connection.fromSubject = function (subject) { var conn = new Connection(); conn.restoreFromSubject(subject); return conn; -} +}; // Functions below may include legacy code from the first version of Collusion. // Find the page the URL was originally loaded from to determine whether this @@ -142,8 +143,9 @@ Connection.prototype.restoreFromSubject = function (event) { var source = channel.referrer; var target = channel.URI; var targetDomain = getDomain(target.host); + var tab = null; try { - var tab = getTabForChannel(channel); + tab = getTabForChannel(channel); } catch (e) { console.log('EXCEPTION CAUGHT: No tab for connection'); tab = null; @@ -154,7 +156,7 @@ Connection.prototype.restoreFromSubject = function (event) { var browserSpec = browserUri && browserUri.spec; var browserDomain = null; try { - var browserDomain = browserUri && getDomain(browserUri.host); + browserDomain = browserUri && getDomain(browserUri.host); } catch (e) { // chances are the URL is about:blank, which has no host and throws an exception // console.error('Error getting host from: ' + browserUri.spec); @@ -236,7 +238,7 @@ Connection.prototype.restoreFromSubject = function (event) { this.isPrivate = isPrivate; this._sourceTab = tab; // Never logged, only for associating data with current tab // console.error((sourceVisited ? 'site: ' : 'tracker: ') + sourceDomain + ' -> ' + targetDomain + ' (' + browserUri.spec + ')'); -} +}; // Connection - level methods (not on instances) // This may be supported by the addon-sdk events.on now. diff --git a/lib/main.js b/lib/main.js index c5aebe3..0b02372 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,3 +1,5 @@ +/* jshint moz: true */ +/* global exports, require */ "use strict"; const events = require("sdk/system/events"); @@ -66,4 +68,4 @@ exports.main = function (options, callbacks) { return; } tabs.open(data.url(loadURL)); -} +}; diff --git a/lib/persist.js b/lib/persist.js index 1c5fb7c..cc24623 100644 --- a/lib/persist.js +++ b/lib/persist.js @@ -1,3 +1,5 @@ +/* jshint moz: true */ +/* global console, require, exports */ // All writes to storage and upload logic in the addon process goes here. "use strict"; @@ -11,7 +13,7 @@ var storage = ss.storage; const STORAGE_KEYS = [ "blockmap", "connections", -] +]; // Upload logic. function serializeConnections(connections) { @@ -20,7 +22,7 @@ function serializeConnections(connections) { version: '1.1', uploadTime: Date.now(), connections: connections - } + }; return JSON.stringify(exportSet); } @@ -63,7 +65,7 @@ exports.storeConnections = function storeConnections(connections) { if (prefs.contributeData) { upload(connections); } -} +}; // Reset stored state, including preferences exports.reset = function reset() { @@ -72,7 +74,7 @@ exports.reset = function reset() { prefs.contributeData = false; prefs.defaultVisualization = "graph"; prefs.defaultFilter = "daily"; -} +}; // Initialize all of our storage if (!storage.connections) { diff --git a/lib/shared/menuitems.js b/lib/shared/menuitems.js index e00828a..77c0c3c 100644 --- a/lib/shared/menuitems.js +++ b/lib/shared/menuitems.js @@ -1,3 +1,5 @@ +/* jshint moz: true */ +/* global require, exports */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -142,7 +144,9 @@ function addMenuitems(self, options) { // add unloader let unloader = function unloader() { - menuitem.parentNode && menuitem.parentNode.removeChild(menuitem); + if (menuitem.parentNode) { + menuitem.parentNode.removeChild(menuitem); + } menuitems[menuitems_i] = null; }; menuitemNS(self).unloaders.push(function () { @@ -218,17 +222,17 @@ function tryParent(parent, menuitem, before) { return !!parent; } -function insertBefore(parent, insertBefore) { - if (typeof insertBefore == "number") { - switch (insertBefore) { +function insertBefore(parent, before) { + if (typeof before == "number") { + switch (before) { case MenuitemExport.FIRST_CHILD: return parent.firstChild; } return null; - } else if (typeof insertBefore == "string") { - return parent.querySelector("#" + insertBefore); + } else if (typeof before == "string") { + return parent.querySelector("#" + before); } - return insertBefore; + return before; } function MenuitemExport(options) { diff --git a/lib/shared/policy.js b/lib/shared/policy.js index 729a809..2a398d9 100644 --- a/lib/shared/policy.js +++ b/lib/shared/policy.js @@ -1,3 +1,5 @@ +/* jshint moz: true */ +/* global require, exports */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/lib/shared/unload+.js b/lib/shared/unload+.js index 64ce6bf..5b9abd8 100644 --- a/lib/shared/unload+.js +++ b/lib/shared/unload+.js @@ -1,3 +1,5 @@ +/* jshint moz:true */ +/* global require, console, exports */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -38,7 +40,7 @@ var Unloader = exports.Unloader = Class({ callback = function () { container.removeEventListener("unload", windowRemover, false); origCallback(); - } + }; } // Wrap the callback in a function that ignores failures diff --git a/lib/tab/events.js b/lib/tab/events.js index 06495be..f6c1774 100644 --- a/lib/tab/events.js +++ b/lib/tab/events.js @@ -1,3 +1,5 @@ +/* jshint moz: true */ +/* global require, exports */ // Simple onTab handler to figure out what tab a connection corresponds to. 'use strict'; diff --git a/lib/tab/utils.js b/lib/tab/utils.js index 72e4cd2..e62243a 100644 --- a/lib/tab/utils.js +++ b/lib/tab/utils.js @@ -1,3 +1,4 @@ +/* jshint moz: true */ // ChromeTab // // This is a module for getting the tab a channel is loaded in, from the channel @@ -84,14 +85,14 @@ function getLoadContext(aRequest) { var loadContext = aRequest.QueryInterface(Ci.nsIChannel) .notificationCallbacks.getInterface(Ci.nsILoadContext); return loadContext; - } catch (ex) { + } catch (err1) { // fail over to trying the load group try { if (!aRequest.loadGroup) return null; var loadContext = aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext); return loadContext; - } catch (ex) { + } catch (err2) { return null; } } diff --git a/lib/ui.js b/lib/ui.js index cdba8d2..0c9ceeb 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -1,3 +1,5 @@ +/* jshint moz:true */ +/* global require, exports, console */ 'use strict'; const { @@ -46,13 +48,13 @@ exports.onForWorker = function (eventname, handler) { } else { console.log('no uiworker to subscript to order'); } -} +}; exports.emitForWorker = function (eventname, obj) { if (uiworker) { uiworker.port.emit(eventname, obj); } -} +}; // Begin tab handlers. These are for sidebar functionality, which is not // present yet. @@ -86,8 +88,9 @@ ContentPolicy({ origin: origin }) { // ignore URIs with no host + var topLevelDomain; try { - var topLevelDomain = Connection.getDomain(location.host); + topLevelDomain = Connection.getDomain(location.host); } catch (e) { // See Issue 374: https://github.com/mozilla/lightbeam/issues/374 // if there is no host, like in about:what, then the host getter throws @@ -152,13 +155,13 @@ function attachToLightbeamPage(worker) { function onPrefChanged(event) { if ("contributeData" in event) { - prefs.contributeData = event["contributeData"]; + prefs.contributeData = event.contributeData; } if ("defaultVisualization" in event) { - prefs.defaultVisualization = event["defaultVisualization"]; + prefs.defaultVisualization = event.defaultVisualization; } if ("defaultFilter" in event) { - prefs.defaultFilter = event["defaultFilter"]; + prefs.defaultFilter = event.defaultFilter; } } From bade2f499ecf1812829128cf2e1af0b934180c3d Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Fri, 25 Apr 2014 11:52:44 +1200 Subject: [PATCH 3/4] Remove unnecessary execute bits on files These files should not be executable --- data/font-awesome.css | 0 data/font/OpenSans-Bold.ttf | Bin data/font/OpenSans-BoldItalic.ttf | Bin data/font/OpenSans-Light.ttf | Bin data/font/OpenSans-LightItalic.ttf | Bin data/font/fontawesome-webfont.woff | Bin data/parseuri.js | 0 .../lib/font/league_gothic-webfont.eot | Bin .../plugin/markdown/markdown.js | 0 .../plugin/math/math.js | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 data/font-awesome.css mode change 100755 => 100644 data/font/OpenSans-Bold.ttf mode change 100755 => 100644 data/font/OpenSans-BoldItalic.ttf mode change 100755 => 100644 data/font/OpenSans-Light.ttf mode change 100755 => 100644 data/font/OpenSans-LightItalic.ttf mode change 100755 => 100644 data/font/fontawesome-webfont.woff mode change 100755 => 100644 data/parseuri.js mode change 100755 => 100644 doc/slides/stanford-workshop-2014-02-25/lib/font/league_gothic-webfont.eot mode change 100755 => 100644 doc/slides/stanford-workshop-2014-02-25/plugin/markdown/markdown.js mode change 100755 => 100644 doc/slides/stanford-workshop-2014-02-25/plugin/math/math.js diff --git a/data/font-awesome.css b/data/font-awesome.css old mode 100755 new mode 100644 diff --git a/data/font/OpenSans-Bold.ttf b/data/font/OpenSans-Bold.ttf old mode 100755 new mode 100644 diff --git a/data/font/OpenSans-BoldItalic.ttf b/data/font/OpenSans-BoldItalic.ttf old mode 100755 new mode 100644 diff --git a/data/font/OpenSans-Light.ttf b/data/font/OpenSans-Light.ttf old mode 100755 new mode 100644 diff --git a/data/font/OpenSans-LightItalic.ttf b/data/font/OpenSans-LightItalic.ttf old mode 100755 new mode 100644 diff --git a/data/font/fontawesome-webfont.woff b/data/font/fontawesome-webfont.woff old mode 100755 new mode 100644 diff --git a/data/parseuri.js b/data/parseuri.js old mode 100755 new mode 100644 diff --git a/doc/slides/stanford-workshop-2014-02-25/lib/font/league_gothic-webfont.eot b/doc/slides/stanford-workshop-2014-02-25/lib/font/league_gothic-webfont.eot old mode 100755 new mode 100644 diff --git a/doc/slides/stanford-workshop-2014-02-25/plugin/markdown/markdown.js b/doc/slides/stanford-workshop-2014-02-25/plugin/markdown/markdown.js old mode 100755 new mode 100644 diff --git a/doc/slides/stanford-workshop-2014-02-25/plugin/math/math.js b/doc/slides/stanford-workshop-2014-02-25/plugin/math/math.js old mode 100755 new mode 100644 From 80a5123af0602e0e558d7c497164983d95b3d4ab Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Mon, 28 Apr 2014 16:39:07 +1200 Subject: [PATCH 4/4] Add a note about running jshint in the CONTRIBUTING file --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 40c6201..10c770c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,3 +6,12 @@ This contributors document should be the canonical place for answers to: What is the code review process? What sort of organizational schema is used for Github Issues? What labels are used, and what do they mean? How are milestones handled? +# Before submitting a pull request + +To install jshint, simply `npm install jshint` from the root directory of the project. Then run like it like this: + + node_modules/.bin/jshint data/*.js + +and make sure your changes are not adding any new warnings or errors. + +Also keep an eye on the command line warnings and errors when running the extension via `cfx run`.