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.
This commit is contained in:
Arlo Breault 2019-07-07 15:40:51 +02:00
parent ebeb45c8d6
commit fab39ae57c
22 changed files with 93 additions and 56 deletions

7
proxy/.eslintignore Normal file
View file

@ -0,0 +1,7 @@
build/
test/
webext/snowflake.js
# FIXME: Whittle these away
spec/
shims.js

View file

@ -1,8 +1,7 @@
{ {
"env": { "env": {
"browser": true, "browser": true,
"es6": true, "es6": true
"node": true
}, },
"extends": "eslint:recommended" "extends": "eslint:recommended"
} }

View file

@ -1,3 +1,5 @@
/* global log, dbg, snowflake */
/* /*
Communication with the snowflake broker. Communication with the snowflake broker.
@ -104,7 +106,7 @@ class Broker {
return xhr.send(payload); return xhr.send(payload);
} }
}; }
Broker.STATUS = { Broker.STATUS = {
OK: 200, OK: 200,

View file

@ -1,5 +1,5 @@
class Config {}; class Config {}
Config.prototype.brokerUrl = 'snowflake-broker.bamsoftware.com'; Config.prototype.brokerUrl = 'snowflake-broker.bamsoftware.com';

View file

@ -1,10 +1,12 @@
/* global TESTING, Util, Query, Params, Config, DebugUI, BadgeUI, UI, Broker, Snowflake */
/* /*
Entry point. Entry point.
*/ */
var snowflake, query, debug, silenceNotifications, log, dbg, init; var snowflake, query, debug, silenceNotifications, log, dbg, init;
;(function() { (function() {
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) { if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
console.log('webrtc feature not detected. shutting down'); console.log('webrtc feature not detected. shutting down');

View file

@ -1,3 +1,5 @@
/* global Config, UI, Broker, Snowflake */
/* /*
Entry point. Entry point.
*/ */

View file

@ -1,10 +1,13 @@
/* global Util, chrome, Config, WebExtUI, Broker, Snowflake */
/* eslint no-unused-vars: 0 */
/* /*
Entry point. Entry point.
*/ */
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications; var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
;(function () { (function () {
silenceNotifications = false; silenceNotifications = false;
debug = false; debug = false;

View file

@ -1,7 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
var fs = require('fs'); /* global require, process */
var { exec, spawn, execSync } = require('child_process');
var { exec, spawn } = require('child_process');
// All files required. // All files required.
var FILES = [ var FILES = [
@ -15,12 +16,6 @@ var FILES = [
'shims.js' 'shims.js'
]; ];
var INITS = [
'init-badge.js',
'init-node.js',
'init-webext.js'
];
var FILES_SPEC = [ var FILES_SPEC = [
'spec/broker.spec.js', 'spec/broker.spec.js',
'spec/init.spec.js', 'spec/init.spec.js',
@ -42,7 +37,7 @@ var copyStaticFiles = function() {
var concatJS = function(outDir, init) { var concatJS = function(outDir, init) {
var files; var files;
files = FILES.concat(`init-${init}.js`); 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) { if (err) {
throw err; throw err;
} }

View file

@ -1,3 +1,5 @@
/* global snowflake, log, dbg, Util, PeerConnection, Snowflake, Parse, WS */
/* /*
Represents a single: Represents a single:
@ -66,15 +68,13 @@ class ProxyPair {
} }
receiveWebRTCOffer(offer) { receiveWebRTCOffer(offer) {
var e, err;
if ('offer' !== offer.type) { if ('offer' !== offer.type) {
log('Invalid SDP received -- was not an offer.'); log('Invalid SDP received -- was not an offer.');
return false; return false;
} }
try { try {
err = this.pc.setRemoteDescription(offer); this.pc.setRemoteDescription(offer);
} catch (error) { } catch (error) {
e = error;
log('Invalid SDP message.'); log('Invalid SDP message.');
return false; return false;
} }
@ -233,7 +233,7 @@ class ProxyPair {
return void 0 === ws || WebSocket.CLOSED === ws.readyState; return void 0 === ws || WebSocket.CLOSED === ws.readyState;
} }
}; }
ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024; ProxyPair.prototype.MAX_BUFFER = 10 * 1024 * 1024;

View file

@ -1,3 +1,5 @@
/* global module, require */
/* /*
WebRTC shims for multiple browsers. WebRTC shims for multiple browsers.
*/ */

View file

@ -1,3 +1,5 @@
/* global log, dbg, DummyRateLimit, BucketRateLimit, SessionDescription, ProxyPair */
/* /*
A JavaScript WebRTC snowflake proxy A JavaScript WebRTC snowflake proxy
@ -79,7 +81,7 @@ class Snowflake {
} else { } else {
return pair.active = false; return pair.active = false;
} }
}, function(err) { }, function() {
return pair.active = false; return pair.active = false;
}); });
return this.retries++; return this.retries++;
@ -90,7 +92,7 @@ class Snowflake {
if (this.proxyPairs.length < this.config.connectionsPerClient) { if (this.proxyPairs.length < this.config.connectionsPerClient) {
return this.makeProxyPair(this.relayAddr); return this.makeProxyPair(this.relayAddr);
} }
return this.proxyPairs.find(function(pp, i, arr) { return this.proxyPairs.find(function(pp) {
return !pp.active; return !pp.active;
}); });
} }
@ -130,7 +132,7 @@ class Snowflake {
var pair; var pair;
pair = new ProxyPair(relay, this.rateLimit, this.config.pcConfig); pair = new ProxyPair(relay, this.rateLimit, this.config.pcConfig);
this.proxyPairs.push(pair); this.proxyPairs.push(pair);
pair.onCleanup = (event) => { pair.onCleanup = () => {
var ind; var ind;
// Delete from the list of active proxy pairs. // Delete from the list of active proxy pairs.
ind = this.proxyPairs.indexOf(pair); ind = this.proxyPairs.indexOf(pair);
@ -154,7 +156,7 @@ class Snowflake {
return results; return results;
} }
}; }
Snowflake.prototype.relayAddr = null; Snowflake.prototype.relayAddr = null;

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, spyOn, Broker */
/* /*
jasmine tests for Snowflake broker jasmine tests for Snowflake broker
*/ */

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, Snowflake, UI */
// Fake snowflake to interact with // Fake snowflake to interact with
var snowflake = { var snowflake = {

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, spyOn */
/* /*
jasmine tests for Snowflake proxypair jasmine tests for Snowflake proxypair
*/ */

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, spyOn, Snowflake, Config, UI */
/* /*
jasmine tests for Snowflake jasmine tests for Snowflake
*/ */
@ -7,34 +9,34 @@ class PeerConnection {
setRemoteDescription() { setRemoteDescription() {
return true; return true;
} }
send(data) {} send() {}
}; }
class SessionDescription {}; class SessionDescription {}
SessionDescription.prototype.type = 'offer'; SessionDescription.prototype.type = 'offer';
class WebSocket { class WebSocket {
constructor() { constructor() {
this.bufferedAmount = 0; this.bufferedAmount = 0;
} }
send(data) {} send() {}
}; }
WebSocket.prototype.OPEN = 1; WebSocket.prototype.OPEN = 1;
WebSocket.prototype.CLOSED = 0; WebSocket.prototype.CLOSED = 0;
var log = function() {}; var log = function() {};
var config = new Config; var config = new Config();
var ui = new UI; var ui = new UI();
class FakeBroker { class FakeBroker {
getClientOffer() { getClientOffer() {
return new Promise(function(F, R) { return new Promise(function() {
return {}; return {};
}); });
} }
}; }
describe('Snowflake', function() { describe('Snowflake', function() {

View file

@ -1,8 +1,12 @@
/* global expect, it, describe, spyOn, DebugUI, BadgeUI */
/* eslint no-redeclare: 0 */
/* /*
jasmine tests for Snowflake UI jasmine tests for Snowflake UI
*/ */
var document = { var document = {
getElementById: function(id) { getElementById: function() {
return {}; return {};
}, },
createTextNode: function(txt) { createTextNode: function(txt) {

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, Parse, Query, Params */
/* /*
jasmine tests for Snowflake utils jasmine tests for Snowflake utils
*/ */

View file

@ -1,3 +1,5 @@
/* global expect, it, describe, WS */
/* /*
jasmine tests for Snowflake websocket jasmine tests for Snowflake websocket
*/ */

View file

@ -1,18 +1,20 @@
/* global chrome, log, update */
/* /*
All of Snowflake's DOM manipulation and inputs. All of Snowflake's DOM manipulation and inputs.
*/ */
class UI { class UI {
setStatus(msg) {} setStatus() {}
setActive(connected) { setActive(connected) {
return this.active = connected; return this.active = connected;
} }
log(msg) {} log() {}
}; }
UI.prototype.active = false; UI.prototype.active = false;
@ -31,7 +33,7 @@ class BadgeUI extends UI {
return this.$badge.className = connected ? 'active' : ''; return this.$badge.className = connected ? 'active' : '';
} }
}; }
BadgeUI.prototype.$badge = null; BadgeUI.prototype.$badge = null;
@ -67,7 +69,7 @@ class DebugUI extends UI {
return this.$msglog.scrollTop = this.$msglog.scrollHeight; return this.$msglog.scrollTop = this.$msglog.scrollHeight;
} }
}; }
// DOM elements references. // DOM elements references.
DebugUI.prototype.$msglog = null; DebugUI.prototype.$msglog = null;
@ -96,14 +98,13 @@ class WebExtUI extends UI {
} }
initToggle() { initToggle() {
var getting; chrome.storage.local.get("snowflake-enabled", (result) => {
return getting = chrome.storage.local.get("snowflake-enabled", (result) => {
if (result['snowflake-enabled'] !== void 0) { if (result['snowflake-enabled'] !== void 0) {
this.enabled = result['snowflake-enabled']; this.enabled = result['snowflake-enabled'];
} else { } else {
log("Toggle state not yet saved"); 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) { onMessage(m) {
var storing;
this.enabled = m.enabled; this.enabled = m.enabled;
this.setEnabled(this.enabled); this.setEnabled(this.enabled);
this.postActive(); this.postActive();
return storing = chrome.storage.local.set({ chrome.storage.local.set({
"snowflake-enabled": this.enabled "snowflake-enabled": this.enabled
}, function() { }, function() {
return log("Stored toggle state"); log("Stored toggle state");
}); });
} }
onDisconnect(port) { onDisconnect() {
return this.port = null; this.port = null;
} }
setActive(connected) { setActive(connected) {
@ -171,7 +171,7 @@ class WebExtUI extends UI {
}); });
} }
}; }
WebExtUI.prototype.port = null; WebExtUI.prototype.port = null;

View file

@ -1,3 +1,6 @@
/* global log */
/* exported Query, Params, DummyRateLimit */
/* /*
A JavaScript WebRTC snowflake proxy A JavaScript WebRTC snowflake proxy
@ -34,7 +37,7 @@ class Util {
return typeof PeerConnection === 'function'; return typeof PeerConnection === 'function';
} }
}; }
// It would not be effective for Tor Browser users to run the proxy. // 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 // 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('&'); return parts.join('&');
} }
}; }
class Parse { class Parse {
@ -203,7 +206,7 @@ class Parse {
} }
} }
}; }
class Params { class Params {
@ -257,7 +260,7 @@ class Params {
return val; return val;
} }
}; }
class BucketRateLimit { class BucketRateLimit {
@ -295,7 +298,7 @@ class BucketRateLimit {
return this.amount > this.capacity; return this.amount > this.capacity;
} }
}; }
BucketRateLimit.prototype.amount = 0.0; BucketRateLimit.prototype.amount = 0.0;
@ -310,7 +313,7 @@ class DummyRateLimit {
this.time = time; this.time = time;
} }
update(n) { update() {
return true; return true;
} }
@ -322,4 +325,4 @@ class DummyRateLimit {
return false; return false;
} }
}; }

View file

@ -1,3 +1,5 @@
/* global chrome */
const port = chrome.runtime.connect({ const port = chrome.runtime.connect({
name: "popup" name: "popup"
}); });

View file

@ -1,3 +1,5 @@
/* global Query */
/* /*
Only websocket-specific stuff. Only websocket-specific stuff.
*/ */
@ -27,7 +29,7 @@ class WS {
if (!path.match(/^\//)) { if (!path.match(/^\//)) {
path = '/' + path; path = '/' + path;
} }
path = path.replace(/[^\/]+/, function(m) { path = path.replace(/[^/]+/, function(m) {
return encodeURIComponent(m); return encodeURIComponent(m);
}); });
parts.push(path); parts.push(path);
@ -54,7 +56,7 @@ class WS {
return ws; return ws;
} }
}; }
WS.WSS_ENABLED = true; WS.WSS_ENABLED = true;