[tor-commits] [snowflake/master] Cleanup lints identified by eslint

arlo at torproject.org arlo at torproject.org
Wed Jul 10 15:58:46 UTC 2019


commit fab39ae57c8c8ba0a65ec381e8b9678468e45164
Author: Arlo Breault <arlolra at gmail.com>
Date:   Sun Jul 7 15:40:51 2019 +0200

    Cleanup lints identified by eslint
    
    Some files were omitted in the .eslintignore, left as an exercise to the
    reader.
    
    We probably want to reduce amount of globals overall and use proper es
    modules.
---
 proxy/.eslintignore          |  7 +++++++
 proxy/.eslintrc.json         |  3 +--
 proxy/broker.js              |  4 +++-
 proxy/config.js              |  2 +-
 proxy/init-badge.js          |  4 +++-
 proxy/init-node.js           |  2 ++
 proxy/init-webext.js         |  5 ++++-
 proxy/make.js                | 13 ++++---------
 proxy/proxypair.js           |  8 ++++----
 proxy/shims.js               |  2 ++
 proxy/snowflake.js           | 10 ++++++----
 proxy/spec/broker.spec.js    |  2 ++
 proxy/spec/init.spec.js      |  2 ++
 proxy/spec/proxypair.spec.js |  2 ++
 proxy/spec/snowflake.spec.js | 20 +++++++++++---------
 proxy/spec/ui.spec.js        |  6 +++++-
 proxy/spec/util.spec.js      |  2 ++
 proxy/spec/websocket.spec.js |  2 ++
 proxy/ui.js                  | 28 ++++++++++++++--------------
 proxy/util.js                | 17 ++++++++++-------
 proxy/webext/popup.js        |  2 ++
 proxy/websocket.js           |  6 ++++--
 22 files changed, 93 insertions(+), 56 deletions(-)

diff --git a/proxy/.eslintignore b/proxy/.eslintignore
new file mode 100644
index 0000000..f580632
--- /dev/null
+++ b/proxy/.eslintignore
@@ -0,0 +1,7 @@
+build/
+test/
+webext/snowflake.js
+
+# FIXME: Whittle these away
+spec/
+shims.js
diff --git a/proxy/.eslintrc.json b/proxy/.eslintrc.json
index d6f8309..f94ba96 100644
--- a/proxy/.eslintrc.json
+++ b/proxy/.eslintrc.json
@@ -1,8 +1,7 @@
 {
     "env": {
         "browser": true,
-        "es6": true,
-        "node": true
+        "es6": true
     },
     "extends": "eslint:recommended"
 }
diff --git a/proxy/broker.js b/proxy/broker.js
index 4e287b4..9806e76 100644
--- a/proxy/broker.js
+++ b/proxy/broker.js
@@ -1,3 +1,5 @@
+/* global log, dbg, snowflake */
+
 /*
 Communication with the snowflake broker.
 
@@ -104,7 +106,7 @@ class Broker {
     return xhr.send(payload);
   }
 
-};
+}
 
 Broker.STATUS = {
   OK: 200,
diff --git a/proxy/config.js b/proxy/config.js
index d5d8ef7..af8bc02 100644
--- a/proxy/config.js
+++ b/proxy/config.js
@@ -1,5 +1,5 @@
 
-class Config {};
+class Config {}
 
 Config.prototype.brokerUrl = 'snowflake-broker.bamsoftware.com';
 
diff --git a/proxy/init-badge.js b/proxy/init-badge.js
index 180a963..1a887a1 100644
--- a/proxy/init-badge.js
+++ b/proxy/init-badge.js
@@ -1,10 +1,12 @@
+/* global TESTING, Util, Query, Params, Config, DebugUI, BadgeUI, UI, Broker, Snowflake */
+
 /*
 Entry point.
 */
 
 var snowflake, query, debug, silenceNotifications, log, dbg, init;
 
-;(function() {
+(function() {
 
   if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
     console.log('webrtc feature not detected. shutting down');
diff --git a/proxy/init-node.js b/proxy/init-node.js
index 9efd486..789e6e3 100644
--- a/proxy/init-node.js
+++ b/proxy/init-node.js
@@ -1,3 +1,5 @@
+/* global Config, UI, Broker, Snowflake */
+
 /*
 Entry point.
 */
diff --git a/proxy/init-webext.js b/proxy/init-webext.js
index ee755c6..2f4f156 100644
--- a/proxy/init-webext.js
+++ b/proxy/init-webext.js
@@ -1,10 +1,13 @@
+/* global Util, chrome, Config, WebExtUI, Broker, Snowflake */
+/* eslint no-unused-vars: 0 */
+
 /*
 Entry point.
 */
 
 var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
 
-;(function () {
+(function () {
 
   silenceNotifications = false;
   debug = false;
diff --git a/proxy/make.js b/proxy/make.js
index f5f1c0a..b614864 100755
--- a/proxy/make.js
+++ b/proxy/make.js
@@ -1,7 +1,8 @@
 #!/usr/bin/env node
 
-var fs = require('fs');
-var { exec, spawn, execSync } = require('child_process');
+/* global require, process */
+
+var { exec, spawn } = require('child_process');
 
 // All files required.
 var FILES = [
@@ -15,12 +16,6 @@ var FILES = [
   'shims.js'
 ];
 
-var INITS = [
-  'init-badge.js',
-  'init-node.js',
-  'init-webext.js'
-];
-
 var FILES_SPEC = [
   'spec/broker.spec.js',
   'spec/init.spec.js',
@@ -42,7 +37,7 @@ var copyStaticFiles = function() {
 var concatJS = function(outDir, init) {
   var files;
   files = FILES.concat(`init-${init}.js`);
-  return exec(`cat ${files.join(' ')} > ${outDir}/${OUTFILE}`, function(err, stdout, stderr) {
+  return exec(`cat ${files.join(' ')} > ${outDir}/${OUTFILE}`, function(err) {
     if (err) {
       throw err;
     }
diff --git a/proxy/proxypair.js b/proxy/proxypair.js
index 674ac18..6ffa9e5 100644
--- a/proxy/proxypair.js
+++ b/proxy/proxypair.js
@@ -1,3 +1,5 @@
+/* global snowflake, log, dbg, Util, PeerConnection, Snowflake, Parse, WS */
+
 /*
 Represents a single:
 
@@ -66,15 +68,13 @@ class ProxyPair {
   }
 
   receiveWebRTCOffer(offer) {
-    var e, err;
     if ('offer' !== offer.type) {
       log('Invalid SDP received -- was not an offer.');
       return false;
     }
     try {
-      err = this.pc.setRemoteDescription(offer);
+      this.pc.setRemoteDescription(offer);
     } catch (error) {
-      e = error;
       log('Invalid SDP message.');
       return false;
     }
@@ -233,7 +233,7 @@ class ProxyPair {
     return void 0 === ws || WebSocket.CLOSED === ws.readyState;
   }
 
-};
+}
 
 ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;
 
diff --git a/proxy/shims.js b/proxy/shims.js
index 4ddf421..8c88eae 100644
--- a/proxy/shims.js
+++ b/proxy/shims.js
@@ -1,3 +1,5 @@
+/* global module, require */
+
 /*
 WebRTC shims for multiple browsers.
 */
diff --git a/proxy/snowflake.js b/proxy/snowflake.js
index 2c08c4d..bbf3d8b 100644
--- a/proxy/snowflake.js
+++ b/proxy/snowflake.js
@@ -1,3 +1,5 @@
+/* global log, dbg, DummyRateLimit, BucketRateLimit, SessionDescription, ProxyPair */
+
 /*
 A JavaScript WebRTC snowflake proxy
 
@@ -79,7 +81,7 @@ class Snowflake {
       } else {
         return pair.active = false;
       }
-    }, function(err) {
+    }, function() {
       return pair.active = false;
     });
     return this.retries++;
@@ -90,7 +92,7 @@ class Snowflake {
     if (this.proxyPairs.length < this.config.connectionsPerClient) {
       return this.makeProxyPair(this.relayAddr);
     }
-    return this.proxyPairs.find(function(pp, i, arr) {
+    return this.proxyPairs.find(function(pp) {
       return !pp.active;
     });
   }
@@ -130,7 +132,7 @@ class Snowflake {
     var pair;
     pair = new ProxyPair(relay, this.rateLimit, this.config.pcConfig);
     this.proxyPairs.push(pair);
-    pair.onCleanup = (event) => {
+    pair.onCleanup = () => {
       var ind;
       // Delete from the list of active proxy pairs.
       ind = this.proxyPairs.indexOf(pair);
@@ -154,7 +156,7 @@ class Snowflake {
     return results;
   }
 
-};
+}
 
 Snowflake.prototype.relayAddr = null;
 
diff --git a/proxy/spec/broker.spec.js b/proxy/spec/broker.spec.js
index a7c2e1d..4eb3029 100644
--- a/proxy/spec/broker.spec.js
+++ b/proxy/spec/broker.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, spyOn, Broker */
+
 /*
 jasmine tests for Snowflake broker
 */
diff --git a/proxy/spec/init.spec.js b/proxy/spec/init.spec.js
index baa7388..748bc86 100644
--- a/proxy/spec/init.spec.js
+++ b/proxy/spec/init.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, Snowflake, UI */
+
 // Fake snowflake to interact with
 
 var snowflake = {
diff --git a/proxy/spec/proxypair.spec.js b/proxy/spec/proxypair.spec.js
index 924aca0..3716f2d 100644
--- a/proxy/spec/proxypair.spec.js
+++ b/proxy/spec/proxypair.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, spyOn */
+
 /*
 jasmine tests for Snowflake proxypair
 */
diff --git a/proxy/spec/snowflake.spec.js b/proxy/spec/snowflake.spec.js
index eccc24d..970947b 100644
--- a/proxy/spec/snowflake.spec.js
+++ b/proxy/spec/snowflake.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, spyOn, Snowflake, Config, UI */
+
 /*
 jasmine tests for Snowflake
 */
@@ -7,34 +9,34 @@ class PeerConnection {
   setRemoteDescription() {
     return true;
   }
-  send(data) {}
-};
+  send() {}
+}
 
-class SessionDescription {};
+class SessionDescription {}
 SessionDescription.prototype.type = 'offer';
 
 class WebSocket {
   constructor() {
     this.bufferedAmount = 0;
   }
-  send(data) {}
-};
+  send() {}
+}
 WebSocket.prototype.OPEN = 1;
 WebSocket.prototype.CLOSED = 0;
 
 var log = function() {};
 
-var config = new Config;
+var config = new Config();
 
-var ui = new UI;
+var ui = new UI();
 
 class FakeBroker {
   getClientOffer() {
-    return new Promise(function(F, R) {
+    return new Promise(function() {
       return {};
     });
   }
-};
+}
 
 describe('Snowflake', function() {
 
diff --git a/proxy/spec/ui.spec.js b/proxy/spec/ui.spec.js
index 8ae141f..3386a2d 100644
--- a/proxy/spec/ui.spec.js
+++ b/proxy/spec/ui.spec.js
@@ -1,8 +1,12 @@
+/* global expect, it, describe, spyOn, DebugUI, BadgeUI */
+/* eslint no-redeclare: 0 */
+
 /*
 jasmine tests for Snowflake UI
 */
+
 var document = {
-  getElementById: function(id) {
+  getElementById: function() {
     return {};
   },
   createTextNode: function(txt) {
diff --git a/proxy/spec/util.spec.js b/proxy/spec/util.spec.js
index 8f1ff7a..17968b1 100644
--- a/proxy/spec/util.spec.js
+++ b/proxy/spec/util.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, Parse, Query, Params */
+
 /*
 jasmine tests for Snowflake utils
 */
diff --git a/proxy/spec/websocket.spec.js b/proxy/spec/websocket.spec.js
index 370995a..6c2ef2e 100644
--- a/proxy/spec/websocket.spec.js
+++ b/proxy/spec/websocket.spec.js
@@ -1,3 +1,5 @@
+/* global expect, it, describe, WS */
+
 /*
 jasmine tests for Snowflake websocket
 */
diff --git a/proxy/ui.js b/proxy/ui.js
index da14800..54e0897 100644
--- a/proxy/ui.js
+++ b/proxy/ui.js
@@ -1,18 +1,20 @@
+/* global chrome, log, update */
+
 /*
 All of Snowflake's DOM manipulation and inputs.
 */
 
 class UI {
 
-  setStatus(msg) {}
+  setStatus() {}
 
   setActive(connected) {
     return this.active = connected;
   }
 
-  log(msg) {}
+  log() {}
 
-};
+}
 
 UI.prototype.active = false;
 
@@ -31,7 +33,7 @@ class BadgeUI extends UI {
     return this.$badge.className = connected ? 'active' : '';
   }
 
-};
+}
 
 BadgeUI.prototype.$badge = null;
 
@@ -67,7 +69,7 @@ class DebugUI extends UI {
     return this.$msglog.scrollTop = this.$msglog.scrollHeight;
   }
 
-};
+}
 
 // DOM elements references.
 DebugUI.prototype.$msglog = null;
@@ -96,14 +98,13 @@ class WebExtUI extends UI {
   }
 
   initToggle() {
-    var getting;
-    return getting = chrome.storage.local.get("snowflake-enabled", (result) => {
+    chrome.storage.local.get("snowflake-enabled", (result) => {
       if (result['snowflake-enabled'] !== void 0) {
         this.enabled = result['snowflake-enabled'];
       } else {
         log("Toggle state not yet saved");
       }
-      return this.setEnabled(this.enabled);
+      this.setEnabled(this.enabled);
     });
   }
 
@@ -126,19 +127,18 @@ class WebExtUI extends UI {
   }
 
   onMessage(m) {
-    var storing;
     this.enabled = m.enabled;
     this.setEnabled(this.enabled);
     this.postActive();
-    return storing = chrome.storage.local.set({
+    chrome.storage.local.set({
       "snowflake-enabled": this.enabled
     }, function() {
-      return log("Stored toggle state");
+      log("Stored toggle state");
     });
   }
 
-  onDisconnect(port) {
-    return this.port = null;
+  onDisconnect() {
+    this.port = null;
   }
 
   setActive(connected) {
@@ -171,7 +171,7 @@ class WebExtUI extends UI {
     });
   }
 
-};
+}
 
 WebExtUI.prototype.port = null;
 
diff --git a/proxy/util.js b/proxy/util.js
index 6d3651f..073251e 100644
--- a/proxy/util.js
+++ b/proxy/util.js
@@ -1,3 +1,6 @@
+/* global log */
+/* exported Query, Params, DummyRateLimit */
+
 /*
 A JavaScript WebRTC snowflake proxy
 
@@ -34,7 +37,7 @@ class Util {
     return typeof PeerConnection === 'function';
   }
 
-};
+}
 
 // It would not be effective for Tor Browser users to run the proxy.
 // Do we seem to be running in Tor Browser? Check the user-agent string and for
@@ -99,7 +102,7 @@ class Query {
     return parts.join('&');
   }
 
-};
+}
 
 
 class Parse {
@@ -203,7 +206,7 @@ class Parse {
     }
   }
 
-};
+}
 
 
 class Params {
@@ -257,7 +260,7 @@ class Params {
     return val;
   }
 
-};
+}
 
 
 class BucketRateLimit {
@@ -295,7 +298,7 @@ class BucketRateLimit {
     return this.amount > this.capacity;
   }
 
-};
+}
 
 BucketRateLimit.prototype.amount = 0.0;
 
@@ -310,7 +313,7 @@ class DummyRateLimit {
     this.time = time;
   }
 
-  update(n) {
+  update() {
     return true;
   }
 
@@ -322,4 +325,4 @@ class DummyRateLimit {
     return false;
   }
 
-};
+}
diff --git a/proxy/webext/popup.js b/proxy/webext/popup.js
index 435adb1..d8d6464 100644
--- a/proxy/webext/popup.js
+++ b/proxy/webext/popup.js
@@ -1,3 +1,5 @@
+/* global chrome */
+
 const port = chrome.runtime.connect({
   name: "popup"
 });
diff --git a/proxy/websocket.js b/proxy/websocket.js
index 2a124aa..83911da 100644
--- a/proxy/websocket.js
+++ b/proxy/websocket.js
@@ -1,3 +1,5 @@
+/* global Query */
+
 /*
 Only websocket-specific stuff.
 */
@@ -27,7 +29,7 @@ class WS {
       if (!path.match(/^\//)) {
         path = '/' + path;
       }
-      path = path.replace(/[^\/]+/, function(m) {
+      path = path.replace(/[^/]+/, function(m) {
         return encodeURIComponent(m);
       });
       parts.push(path);
@@ -54,7 +56,7 @@ class WS {
     return ws;
   }
 
-};
+}
 
 WS.WSS_ENABLED = true;
 



More information about the tor-commits mailing list