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": {
"browser": true,
"es6": true,
"node": true
"es6": true
},
"extends": "eslint:recommended"
}

View file

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

View file

@ -1,5 +1,5 @@
class Config {};
class Config {}
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.
*/
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');

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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() {

View file

@ -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) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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