[eslint] fix no-unused-vars violations

This commit is contained in:
spalger
2018-05-14 12:16:03 -07:00
parent 898913545a
commit f493527dc4
22 changed files with 93 additions and 117 deletions

View File

@ -1,11 +1,9 @@
describe('Logger Abstract', function () {
var expect = require('expect.js');
var sinon = require('sinon');
var Log = require('../../../src/lib/log');
var LoggerAbstract = require('../../../src/lib/logger');
var parentLog;
var stub = require('../../utils/auto_release_stub').make();
function makeLogger(parent, levels) {
return new LoggerAbstract(parent || parentLog, {

View File

@ -92,7 +92,7 @@ describe('Client Action runner', function () {
describe('clientAction::proxy', function () {
it('proxies to the passed function', function () {
var action = makeClientActionProxy(function (params, cb) {
var action = makeClientActionProxy(function () {
throw new Error('proxy function called');
});
@ -110,7 +110,7 @@ describe('Client Action runner', function () {
});
});
action({}, function (err, params) {
action({}, function () {
expect(client.transport.request).to.be.a('function');
done();
});
@ -126,7 +126,7 @@ describe('Client Action runner', function () {
});
it('supports a param transformation function', function () {
var action = makeClientActionProxy(function (params, cb) {
var action = makeClientActionProxy(function (params) {
expect(params).to.have.property('transformed');
}, {
transform: function (params) {
@ -139,7 +139,7 @@ describe('Client Action runner', function () {
it('returns the proxied function\'s return value', function () {
var football = {};
var action = makeClientActionProxy(function (params, cb) {
var action = makeClientActionProxy(function () {
return football;
});
@ -186,7 +186,7 @@ describe('Client Action runner', function () {
it('rejects date values', function (done) {
action({
one: new Date()
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -196,7 +196,7 @@ describe('Client Action runner', function () {
action({
one: ['one'],
two: [1304]
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -205,7 +205,7 @@ describe('Client Action runner', function () {
it('rejects object', function (done) {
action({
one: { but: 'duration' }
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -242,7 +242,7 @@ describe('Client Action runner', function () {
it('it rejects regexp', function (done) {
action({
one: /regexp!/g
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -253,7 +253,7 @@ describe('Client Action runner', function () {
one: {
pasta: 'sauce'
}
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -302,7 +302,7 @@ describe('Client Action runner', function () {
it('it rejects things not in the list', function (done) {
action({
one: 'not an opt'
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -417,7 +417,7 @@ describe('Client Action runner', function () {
it('rejects dates', function (done) {
action({
one: new Date()
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -426,7 +426,7 @@ describe('Client Action runner', function () {
it('rejects objects', function (done) {
action({
one: {}
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -435,7 +435,7 @@ describe('Client Action runner', function () {
it('rejects arrays', function (done) {
action({
one: []
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -444,7 +444,7 @@ describe('Client Action runner', function () {
it('rejects regexp', function (done) {
action({
one: /pasta/g
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -488,7 +488,7 @@ describe('Client Action runner', function () {
it('rejects dates', function (done) {
action({
one: new Date()
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -497,7 +497,7 @@ describe('Client Action runner', function () {
it('rejects objects', function (done) {
action({
one: {}
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -506,7 +506,7 @@ describe('Client Action runner', function () {
it('rejects arrays', function (done) {
action({
one: []
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -515,7 +515,7 @@ describe('Client Action runner', function () {
it('rejects regexp', function (done) {
action({
one: /pasta/g
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -559,7 +559,7 @@ describe('Client Action runner', function () {
it('rejects objects', function (done) {
action({
one: {}
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -568,7 +568,7 @@ describe('Client Action runner', function () {
it('rejects arrays', function (done) {
action({
one: []
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -577,7 +577,7 @@ describe('Client Action runner', function () {
it('rejects regexp', function (done) {
action({
one: /pasta/g
}, function (err, params) {
}, function (err) {
expect(err).to.be.a(TypeError);
done();
});
@ -732,7 +732,7 @@ describe('Client Action runner', function () {
it('rejects a url if it required params that are not present', function (done) {
action(params({
type: ['type1', 'type2']
}), function (err, resp) {
}), function (err) {
expect(err).to.be.a(TypeError);
params.check();
done();
@ -845,7 +845,7 @@ describe('Client Action runner', function () {
it('enforces required params', function (done) {
action(params({
b: '3w'
}), function (err, resp) {
}), function (err) {
expect(err).to.be.a(TypeError);
params.check();
done();

View File

@ -17,11 +17,13 @@ describe('Connection Abstract', function () {
it('requires a valid host', function () {
expect(function () {
var conn = new ConnectionAbstract();
// eslint-disable-next-line no-new
new ConnectionAbstract();
}).to.throwError(TypeError);
expect(function () {
var conn = new ConnectionAbstract({});
// eslint-disable-next-line no-new
new ConnectionAbstract({});
}).to.throwError(TypeError);
});

View File

@ -20,7 +20,7 @@ function makeLogger(parent, levels) {
return new ConsoleLogger(parent, config);
}
var stub = require('../../utils/auto_release_stub').make();
require('../../utils/auto_release_stub').make();
describe('Console Logger', function () {

View File

@ -79,7 +79,7 @@ describe('File Logger', function () {
once.call(process, event, handler);
});
var logger = makeLogger();
makeLogger();
expect(function () {
// call the event handler

View File

@ -1,5 +1,4 @@
var Host = require('../../../src/lib/host');
var _ = require('lodash');
var expect = require('expect.js');
var url = require('url');
var expectSubObject = require('../../utils/expect_sub_object');

View File

@ -3,15 +3,12 @@ describe('Http Connector', function () {
var _ = require('lodash');
var expect = require('expect.js');
var nock = require('nock');
var sinon = require('sinon');
var util = require('util');
var parseUrl = require('url').parse;
var http = require('http');
var https = require('https');
var AgentKeepAlive = require('agentkeepalive');
var Host = require('../../../src/lib/host');
var errors = require('../../../src/lib/errors');
var HttpConnection = require('../../../src/lib/connectors/http');
var ConnectionAbstract = require('../../../src/lib/connection');
@ -62,7 +59,8 @@ describe('Http Connector', function () {
it('expects the host to have a protocol of http or https', function () {
expect(function () {
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
// eslint-disable-next-line no-new
new HttpConnection(new Host('thrifty://es.com/stuff'));
}).to.throwError(/invalid protocol/i);
});
@ -254,7 +252,7 @@ describe('Http Connector', function () {
stub(con.log, 'error');
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
con.request({}, function () {
expect(con.log.error.callCount).to.eql(0);
done();
});
@ -264,7 +262,7 @@ describe('Http Connector', function () {
var con = new HttpConnection(new Host('https://google.com'));
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :(')));
con.request({}, function (err, resp, status) {
con.request({}, function (err) {
expect(err).to.be.an(Error);
expect(err.message).to.eql('no more message :(');
done();
@ -275,7 +273,7 @@ describe('Http Connector', function () {
var con = new HttpConnection(new Host('https://google.com'));
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
con.request({}, function (err, resp) {
expect(resp).to.be(undefined);
done();
});
@ -414,7 +412,7 @@ describe('Http Connector', function () {
stub(http.ClientRequest.prototype, 'setNoDelay');
var server = nock('http://localhost').get('/').reply(200);
con.request({}, function (err, resp, status) {
con.request({}, function () {
expect(http.ClientRequest.prototype.setNoDelay.callCount).to.eql(1);
expect(http.ClientRequest.prototype.setNoDelay.lastCall.args[0]).to.eql(true);
server.done();
@ -433,7 +431,7 @@ describe('Http Connector', function () {
con.request({
body: body
}, function (err, resp, status) {
}, function () {
expect(http.ClientRequest.prototype.setHeader.args.find((arg) => arg[0] === 'Content-Length')).to.eql(['Content-Length', 14]);
server.done();
done();
@ -452,7 +450,7 @@ describe('Http Connector', function () {
.once()
.reply(200, respBody);
con.request({}, function (err, resp, status) {
con.request({}, function (err, resp) {
expect(resp).to.be(respBody);
server.done();
done();
@ -468,7 +466,7 @@ describe('Http Connector', function () {
.once()
.reply(200, respBody);
con.request({}, function (err, resp, status) {
con.request({}, function (err, resp) {
expect(resp).to.be(respBody);
server.done();
done();

View File

@ -134,7 +134,7 @@ describe('Log class', function () {
log = new Log({
log: [
{
type: function (log, config) {
type: function (log) {
log.on('error', _.noop);
log.on('warning', _.noop);
log.on('info', _.noop);
@ -237,22 +237,28 @@ describe('Log class', function () {
it('rejects numbers and other truthy data-types', function () {
expect(function () {
var log = new Log({ log: 1515 });
// eslint-disable-next-line no-new
new Log({ log: 1515 });
}).to.throwError(/invalid logging output config/i);
expect(function () {
var log = new Log({ log: /regexp/ });
// eslint-disable-next-line no-new
new Log({ log: /regexp/ });
}).to.throwError(/invalid logging output config/i);
expect(function () {
var log = new Log({ log: new Date() });
// eslint-disable-next-line no-new
new Log({ log: new Date() });
}).to.throwError(/invalid logging output config/i);
expect(function () {
var log = new Log({ log: [1515] });
// eslint-disable-next-line no-new
new Log({ log: [1515] });
}).to.throwError(/invalid logging output config/i);
expect(function () {
var log = new Log({ log: [/regexp/] });
// eslint-disable-next-line no-new
new Log({ log: [/regexp/] });
}).to.throwError(/invalid logging output config/i);
expect(function () {
var log = new Log({ log: [new Date()] });
// eslint-disable-next-line no-new
new Log({ log: [new Date()] });
}).to.throwError(/invalid logging output config/i);
});
});

View File

@ -31,7 +31,6 @@ describe('Stdio Logger', function () {
var now = '2013-01-01T00:00:00Z';
var nowDate = new Date(now);
var nowTime = nowDate.getTime();
var clock;
beforeEach(function () {
stub.autoRelease(sinon.useFakeTimers(nowTime));

View File

@ -78,7 +78,7 @@ describe('Stream Logger', function () {
once.call(process, event, handler);
});
var logger = makeLogger();
makeLogger();
expect(function () {
// call the event handler

View File

@ -2,7 +2,6 @@ describe('Tracer Logger', function () {
var Log = require('../../../src/lib/log');
var TracerLogger = require('../../../src/lib/loggers/tracer');
var sinon = require('sinon');
var expect = require('expect.js');
var parentLog;

View File

@ -59,7 +59,8 @@ describe('Transport Class', function () {
it('Throws an error when connectionPool config is set wrong', function () {
expect(function () {
var trans = new Transport({
// eslint-disable-next-line no-new
new Transport({
connectionPool: 'pasta'
});
}).to.throwError(/invalid connectionpool/i);
@ -166,7 +167,8 @@ describe('Transport Class', function () {
describe('host config', function () {
it('rejects non-strings/objects', function () {
expect(function () {
var trans = new Transport({
// eslint-disable-next-line no-new
new Transport({
host: [
'localhost',
9393
@ -175,7 +177,8 @@ describe('Transport Class', function () {
}).to.throwError(TypeError);
expect(function () {
var trans = new Transport({
// eslint-disable-next-line no-new
new Transport({
host: [
[9292]
]
@ -287,7 +290,8 @@ describe('Transport Class', function () {
it('calls _.shuffle be default', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
var trans = new Transport({
// eslint-disable-next-line no-new
new Transport({
hosts: 'localhost'
});
@ -296,7 +300,8 @@ describe('Transport Class', function () {
it('skips the call to _.shuffle when false', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
var trans = new Transport({
// eslint-disable-next-line no-new
new Transport({
hosts: 'localhost',
randomizeHosts: false
});

View File

@ -1,6 +1,5 @@
var Transport = require('../../../src/lib/transport');
var ConnectionPool = require('../../../src/lib/connection_pool');
var Host = require('../../../src/lib/host');
var errors = require('../../../src/lib/errors');
var expect = require('expect.js');
@ -10,21 +9,6 @@ var through2 = require('through2');
var _ = require('lodash');
var stub = require('../../utils/auto_release_stub').make();
/**
* Allows the tests call #request() without it doing anything past trying to select
* a connection.
* @param {Transport} tran - the transport to neuter
*/
function shortCircuitRequest(tran, delay) {
stub(tran.connectionPool, 'select', function (cb) {
setTimeout(cb, delay);
});
}
function getConnection(transport, status) {
return transport.connectionPool.getConnections(status || 'alive', 1).pop();
}
describe('Transport + Mock server', function () {
describe('#request', function () {
describe('server responds', function () {
@ -209,7 +193,7 @@ describe('Transport + Mock server', function () {
trans.request({
path: '/',
}, function (err, body, status) {
}, function (err, body) {
expect(err).to.be(undefined);
expect(body).to.eql({
'the answer': 42
@ -228,7 +212,7 @@ describe('Transport + Mock server', function () {
trans.request({
path: '/hottie-threads',
}, function (err, body, status) {
}, function (err, body) {
expect(err).to.be(undefined);
expect(body).to.match(/s?he said/g);
done();
@ -239,7 +223,7 @@ describe('Transport + Mock server', function () {
describe('return value', function () {
it('resolves the promise it with the response body', function (done) {
var serverMock = nock('http://esbox.1.com')
nock('http://esbox.1.com')
.get('/')
.reply(200, {
good: 'day'
@ -266,7 +250,7 @@ describe('Transport + Mock server', function () {
host: 'http://localhost:9200'
});
var server = nock('http://localhost:9200')
nock('http://localhost:9200')
.get('/')
.reply(200, {
i: 'am here'
@ -286,7 +270,7 @@ describe('Transport + Mock server', function () {
host: 'http://localhost:9200'
});
var server = nock('http://localhost:9200')
nock('http://localhost:9200')
.get('/')
.delay(1000)
.reply(200, {
@ -295,7 +279,7 @@ describe('Transport + Mock server', function () {
tran.request({
requestTimeout: 25
}, function (err, resp, status) {
}, function (err) {
expect(err).to.be.a(errors.RequestTimeout);
done();
});
@ -307,7 +291,7 @@ describe('Transport + Mock server', function () {
var clock = sinon.useFakeTimers('setTimeout');
stub.autoRelease(clock);
var serverMock = nock('http://esbox.1.com')
nock('http://esbox.1.com')
.get('/')
.reply(200, function () {
var str = through2(function (chunk, enc, cb) {
@ -338,7 +322,7 @@ describe('Transport + Mock server', function () {
.then(function () {
throw new Error('expected the request to fail');
})
.catch(function (err) {
.catch(function () {
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
expect(tran.sniff.callCount).to.eql(0);
expect(_.size(clock.timers)).to.eql(1);