Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #177 from mozilla-services/eslint-take2
Browse files Browse the repository at this point in the history
Add support for eslint and update the code with the new rules
  • Loading branch information
Natim committed Aug 22, 2014
2 parents fd6a662 + 16571ae commit fed4501
Show file tree
Hide file tree
Showing 25 changed files with 293 additions and 172 deletions.
96 changes: 96 additions & 0 deletions .eslintrc
@@ -0,0 +1,96 @@
# http://eslint.org/docs/rules/

env:
"amd": true
"browser": false
"mocha": true
"node": true

rules:
"no-alert": 2
"no-array-constructor": 2
"no-bitwise": 1
"no-caller": 2
"no-catch-shadow": 2
"no-comma-dangle": 2
"no-console": 0
"no-control-regex": 2
"no-debugger": 2
"no-delete-var": 2
"no-div-regex": 2
"no-dupe-keys": 2
"no-else-return": 0
"no-empty": 2
"no-empty-class": 2
"no-empty-label": 2
"no-eq-null": 2
"no-eval": 2
"no-ex-assign": 2
"no-fallthrough": 2
"no-floating-decimal": 2
"no-func-assign": 2
"no-global-strict": 0
"no-implied-eval": 2
"no-iterator": 2
"no-label-var": 2
"no-loop-func": 2
"no-mixed-requires": [0, false]
"no-multi-str": 2
"no-native-reassign": 2
"no-new": 0
"no-new-func": 2
"no-new-object": 2
"no-new-wrappers": 2
"no-obj-calls": 2
"no-octal": 2
"no-octal-escape": 2
"no-plusplus": 0
"no-proto": 2
"no-redeclare": 2
"no-regex-spaces": 2
"no-return-assign": 2
"no-script-url": 2
"no-self-compare": 2
"no-shadow": 2
"no-sync": 0
"no-ternary": 0
"no-undef": 2
"no-undef-init": 2
"no-underscore-dangle": 0
"no-unreachable": 2
"no-unused-expressions": 0
"no-unused-vars": 1
"no-use-before-define": 0
"no-with": 2
"no-wrap-func": 2
"no-yoda": 0
"block-scoped-var": 0
"brace-style": 0
"camelcase": 0
"complexity": [0, 11]
"consistent-return": 0
"consistent-this": [0, "that"]
"curly": 0
"dot-notation": 0
"eqeqeq": 2
"guard-for-in": 0
"max-depth": [0, 4]
"max-len": [0, 80, 4]
"max-params": [0, 3]
"max-statements": [0, 10]
"new-cap": 0
"new-parens": 2
"one-var": 0
"quote-props": 0
"quotes": [0, "single"]
"radix": 0
"semi": 0
"strict": 0
"unnecessary-strict": 0
"use-isnan": 2
"valid-jsdoc": 0
"wrap-iife": 2
"wrap-regex": 0
"no-path-concat": 0
"no-process-exit": 0
"eol-last": 2
28 changes: 0 additions & 28 deletions .jshintrc

This file was deleted.

8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -16,7 +16,7 @@ install:
@npm install

.PHONY: lint
lint: jshint
lint: eslint

clean:
rm -rf .venv node_modules coverage lib-cov html-report
Expand All @@ -28,9 +28,9 @@ cover-mocha:
$(NODE_LOCAL_BIN)/_mocha -- --reporter spec -t 5000 test/*
@echo aim your browser at coverage/lcov-report/index.html for details

.PHONY: jshint
jshint:
@$(NODE_LOCAL_BIN)/jshint test loop/*.js loop/*/*.js
.PHONY: eslint
eslint:
@$(NODE_LOCAL_BIN)/eslint test/*.js loop/*.js loop/*/*.js

.PHONY: mocha
mocha:
Expand Down
1 change: 0 additions & 1 deletion loadtests/loadtest.py
Expand Up @@ -79,7 +79,6 @@ def _handle_caller(message_data):
callee_ws.receive()

elif messageType == "progress" and state == "alerting":
gevent.sleep(25)
self._send_ws_message(
caller_ws,
messageType="action",
Expand Down
1 change: 1 addition & 0 deletions loop/auth.js
Expand Up @@ -110,6 +110,7 @@ module.exports = function(conf, logError, storage, statsdClient) {
// generate the hawk session.
hawk.generateHawkSession(createHawkSession,
function(err, tokenId, authKey, sessionToken) {
if (res.serverError(err)) return;
var hawkIdHmac = hmac(tokenId, conf.get("hawkIdSecret"));
var encryptedIdentifier = encrypt(tokenId, identifier);
storage.setHawkUser(userHmac, hawkIdHmac, function(err) {
Expand Down
8 changes: 4 additions & 4 deletions loop/config.js
Expand Up @@ -6,7 +6,7 @@

var convict = require('convict');
var format = require('util').format;
var crypto = require('crypto');
var getHashes = require('crypto').getHashes;
var path = require('path');
var fs = require('fs');

Expand Down Expand Up @@ -133,7 +133,7 @@ var conf = convict({
userMacAlgorithm: {
doc: "The algorithm that should be used to mac userIds",
format: function(val) {
if (crypto.getHashes().indexOf(val) === -1) {
if (getHashes().indexOf(val) === -1) {
throw new Error("Given hmac algorithm is not supported");
}
},
Expand Down Expand Up @@ -334,15 +334,15 @@ var conf = convict({
doc: "An array of push server URIs",
format: Array,
default: ["wss://push.services.mozilla.com/"]
},
}
});


// handle configuration files. you can specify a CSV list of configuration
// files to process, which will be overlayed in order, in the CONFIG_FILES
// environment variable. By default, the ../config/<env>.json file is loaded.

var envConfig = path.join(__dirname + '/../config', conf.get('env') + '.json');
var envConfig = path.join(__dirname, '/../config', conf.get('env') + '.json');
var files = (envConfig + ',' + process.env.CONFIG_FILES)
.split(',')
.filter(fs.existsSync);
Expand Down
2 changes: 2 additions & 0 deletions loop/fxa.js
Expand Up @@ -7,7 +7,9 @@
var https = require('https');
var request = require('request');
var conf = require('./config').conf;
/*eslint-disable */
var atob = require('atob');
/* eslint-enable */
var sendError = require("./utils").sendError;
var errors = require("./errno.json");

Expand Down
4 changes: 2 additions & 2 deletions loop/hmac.js
Expand Up @@ -6,7 +6,7 @@

var conf = require("./config").conf;
var hexKeyOfSize = require('./config').hexKeyOfSize;
var crypto = require('crypto');
var createHmac = require('crypto').createHmac;

/**
* Returns the HMac digest of the given payload.
Expand All @@ -30,7 +30,7 @@ function hmac(payload, secret, algorithm) {
if (algorithm === undefined) {
algorithm = conf.get("userMacAlgorithm");
}
var _hmac = crypto.createHmac(algorithm, new Buffer(secret, "hex"));
var _hmac = createHmac(algorithm, new Buffer(secret, "hex"));
_hmac.write(payload);
_hmac.end();
return _hmac.read().toString('hex');
Expand Down
6 changes: 4 additions & 2 deletions loop/index.js
Expand Up @@ -23,11 +23,13 @@ var handle503 = require("./middlewares").handle503;
var logMetrics = require('./middlewares').logMetrics;
var websockets = require('./websockets');

var TokBox;

if (conf.get("fakeTokBox") === true) {
console.log("Calls to TokBox are now mocked.");
var TokBox = require('./tokbox').FakeTokBox;
TokBox = require('./tokbox').FakeTokBox;
} else {
var TokBox = require('./tokbox').TokBox;
TokBox = require('./tokbox').TokBox;
}

var getStorage = require('./storage');
Expand Down
3 changes: 1 addition & 2 deletions loop/routes/call-url.js
Expand Up @@ -74,9 +74,8 @@ module.exports = function (app, conf, logError, storage, auth, validators,
sendError(res, 403, errors.INVALID_AUTH_TOKEN, "Forbidden");
return;
}
storage.revokeURLToken(req.token, function(err, record) {
storage.revokeURLToken(req.token, function(err) {
if (res.serverError(err)) return;

res.status(204).json();
});
});
Expand Down
12 changes: 6 additions & 6 deletions loop/routes/calls.js
Expand Up @@ -5,7 +5,7 @@
"use strict";

var async = require('async');
var crypto = require("crypto");
var randomBytes = require("crypto").randomBytes;
var decrypt = require("../encrypt").decrypt;
var errors = require('../errno.json');
var hmac = require('../hmac');
Expand Down Expand Up @@ -38,10 +38,10 @@ module.exports = function(app, conf, logError, storage, tokBox, auth,
}

var currentTimestamp = Date.now();
var callId = crypto.randomBytes(16).toString('hex');
var callId = randomBytes(16).toString('hex');

var wsCalleeToken = crypto.randomBytes(16).toString('hex');
var wsCallerToken = crypto.randomBytes(16).toString('hex');
var wsCalleeToken = randomBytes(16).toString('hex');
var wsCallerToken = randomBytes(16).toString('hex');

var callInfo = {
'callId': callId,
Expand Down Expand Up @@ -176,7 +176,7 @@ module.exports = function(app, conf, logError, storage, tokBox, auth,
request.put({
url: simplePushUrl,
form: { version: callInfo.timestamp }
}, function(err) {
}, function() {
// Catch errors.
});
});
Expand Down Expand Up @@ -271,7 +271,7 @@ module.exports = function(app, conf, logError, storage, tokBox, auth,
request.put({
url: simplePushUrl,
form: { version: callInfo.timestamp }
}, function(err) {
}, function() {
// Catch errors.
});
});
Expand Down
2 changes: 1 addition & 1 deletion loop/routes/push-server-config.js
Expand Up @@ -8,7 +8,7 @@ module.exports = function (app, conf) {
app.get('/push-server-config', function(req, res) {
var urls = conf.get('pushServerURIs');
var url = urls[Math.floor(Math.random() * urls.length)];
res.json(200, {
res.status(200).json({
'pushServerURI': url
});
});
Expand Down
22 changes: 19 additions & 3 deletions loop/storage/redis.js
Expand Up @@ -23,14 +23,18 @@ RedisStorage.prototype = {
// delete the SP url if it exists
var self = this;
self._client.lrem('spurl.' + userMac, 0, simplepushURL,
function(err, deleted) {
function(err) {
if (err) {
callback(err);
return;
}
// And add it back.
self._client.lpush('spurl.' + userMac, simplepushURL,
function(err, size) {
if (err) {
callback(err);
return;
}
// Keep the X most recent URLs.
if (size > self._settings.maxSimplePushUrls) {
self._client.ltrim(
Expand Down Expand Up @@ -200,7 +204,11 @@ RedisStorage.prototype = {
});

if (expired.length > 0) {
self._client.srem(expired, function(err, res) {
self._client.srem(expired, function(err) {
if (err) {
callback(err);
return;
}
callback(null, pendingUrls);
});
return;
Expand Down Expand Up @@ -326,12 +334,20 @@ RedisStorage.prototype = {
cb(null, call);
});
}, function(err, results) {
if (err) {
callback(err);
return;
}
callback(null, results);
});
}

if (expired.length > 0) {
self._client.srem(expired, function(err, res) {
self._client.srem(expired, function(err) {
if (err) {
callback(err);
return;
}
getState();
});
return;
Expand Down
6 changes: 3 additions & 3 deletions loop/tokbox.js
Expand Up @@ -4,7 +4,7 @@

"use strict";

var crypto = require('crypto');
var randomBytes = require('crypto').randomBytes;
var request = require('request');
var conf = require('./config').conf;

Expand Down Expand Up @@ -110,15 +110,15 @@ TokBox.prototype = {
}
};

function FakeTokBox(serverURL) {
function FakeTokBox() {
this._counter = 0;
this.serverURL = conf.get("fakeTokBoxURL");
this.apiKey = "falseApiKey";
}

FakeTokBox.prototype = {
_urlSafeBase64RandomBytes: function(number_of_bytes) {
return crypto.randomBytes(number_of_bytes).toString('base64')
return randomBytes(number_of_bytes).toString('base64')
.replace(/\+/g, '-').replace(/\//g, '_');
},

Expand Down

0 comments on commit fed4501

Please sign in to comment.