[eslint] remove exception for no-unused-vars, fix violations

This commit is contained in:
spalger
2017-06-14 19:07:57 -07:00
parent 058569d4f8
commit d63a37dd42
23 changed files with 77 additions and 123 deletions

View File

@ -1,12 +1,9 @@
module.exports = function (branch) {
const path = require('path');
const jsYaml = require('js-yaml');
const YamlFile = require('./yaml_file');
const root = require('find-root')(__dirname);
const rootReq = function (loc) { return require(path.join(root, loc)); };
const _ = rootReq('src/lib/utils');
const utils = rootReq('grunt/utils');
const es = rootReq('src/elasticsearch');
const clientManager = require('./client_manager');
const port = parseInt(process.env.ES_PORT || 9200, 10);
@ -32,8 +29,8 @@ module.exports = function (branch) {
return clientManager.get().clearEs();
});
const files = _.map(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {
return new YamlFile(filename, docs);
_.each(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {
new YamlFile(filename, docs);
});
});

View File

@ -12,20 +12,19 @@ if (Writable) {
// nice and simple for streams 2
MockWritableStream = module.exports = function (opts) {
Writable.call(this, opts);
this._write = function (chunk, encoding, cb) {};
this._write = function () {};
};
util.inherits(MockWritableStream, Writable);
} else {
// Node < 0.10 did not provide a usefull stream abstract
const Stream = require('stream').Stream;
module.exports = MockWritableStream = function (opts) {
module.exports = MockWritableStream = function () {
Stream.call(this);
this.writable = true;
};
util.inherits(MockWritableStream, Stream);
MockWritableStream.prototype.write = function (data) {
MockWritableStream.prototype.write = function () {
if (!this.writable) {
this.emit('error', new Error('stream not writable'));
return false;
@ -41,15 +40,15 @@ if (Writable) {
}
};
MockWritableStream.prototype.end = function (data, encoding, cb) {
MockWritableStream.prototype.end = function (data, encoding) {
if (typeof (data) === 'function') {
cb = data;
// data is a cb
} else if (typeof (encoding) === 'function') {
cb = encoding;
this.write(data);
} else if (arguments.length > 0) {
this.write(data, encoding);
}
this.writable = false;
};

View File

@ -2,18 +2,14 @@
const _ = require('lodash');
const expect = require('expect.js');
const Promise = require('bluebird');
const sinon = require('sinon');
describe('Angular esFactory', function () {
before(function () {
require('../../../src/elasticsearch.angular.js');
});
const uuid = (function () { let i = 0; return function () { return ++i; }; }());
let esFactory;
let $http;
let $rootScope;
let $httpBackend;
function bootstrap(env) {
beforeEach(function () {
@ -37,10 +33,8 @@ describe('Angular esFactory', function () {
});
beforeEach(angular.mock.inject(function ($injector) {
$http = $injector.get('$http');
esFactory = $injector.get('esFactory');
$rootScope = $injector.get('$rootScope');
$httpBackend = $injector.get('$httpBackend');
}));
}
@ -70,7 +64,6 @@ describe('Angular esFactory', function () {
it('returns an error created by calling a method incorrectly', function () {
const client = esFactory({ hosts: null });
let err;
const prom = client.get().then(function () {
throw new Error('expected request to fail');

View File

@ -1,5 +1,4 @@
const expect = require('expect.js');
const Transport = require('../../../src/lib/transport');
describe('elasticsearch namespace', function () {
const es = window.elasticsearch;

View File

@ -1,6 +1,5 @@
/* global $ */
const expect = require('expect.js');
const Transport = require('../../../src/lib/transport');
describe('jQuery.es namespace', function () {
it('is defined on the global jQuery', function () {

View File

@ -48,7 +48,7 @@ module.exports = function (makeLogger) {
once.call(process, event, handler);
});
const logger = makeLogger();
makeLogger();
expect(function () {
// call the event handler

View File

@ -1,4 +1,4 @@
const blanket = require('blanket')({
require('blanket')({
pattern: require('path').join(__dirname, '../../src')
});

View File

@ -1,7 +1,5 @@
const expect = require('expect.js');
const Log = require('../../src/lib/log');
const LoggerAbstract = require('../../src/lib/logger');
const TracerLogger = require('../../src/lib/loggers/tracer');
const now = new Date('2013-03-01T00:00:00Z');
const sinon = require('sinon');
@ -24,7 +22,7 @@ module.exports = function (makeLogger) {
});
it('listens for the loggers\' "closing" event', function () {
const logger = makeLogger(parent);
makeLogger(parent);
expect(parent.listenerCount('closing')).to.eql(1);
});
});
@ -38,7 +36,7 @@ module.exports = function (makeLogger) {
});
it('listens to just error when log is explicitly error', function () {
const logger = makeLogger(parent, 'error');
makeLogger(parent, 'error');
expect(parent.listenerCount('error')).to.eql(1);
expect(parent.listenerCount('warning')).to.eql(0);
expect(parent.listenerCount('info')).to.eql(0);
@ -47,7 +45,7 @@ module.exports = function (makeLogger) {
});
it('listens for all the events when level is "trace"', function () {
const logger = makeLogger(parent, 'trace');
makeLogger(parent, 'trace');
expect(parent.listenerCount('error')).to.eql(1);
expect(parent.listenerCount('warning')).to.eql(1);
expect(parent.listenerCount('info')).to.eql(1);
@ -56,7 +54,7 @@ module.exports = function (makeLogger) {
});
it('listens for specific events when level is an array', function () {
const logger = makeLogger(parent, ['error', 'trace']);
makeLogger(parent, ['error', 'trace']);
expect(parent.listenerCount('error')).to.eql(1);
expect(parent.listenerCount('warning')).to.eql(0);
expect(parent.listenerCount('info')).to.eql(0);
@ -87,7 +85,7 @@ module.exports = function (makeLogger) {
});
it('emits events because something is listening', function () {
const logger = makeLogger(parent, 'trace');
makeLogger(parent, 'trace');
stub(parent, 'emit');
parent.error(new Error('error message'));
@ -142,7 +140,7 @@ module.exports = function (makeLogger) {
describe('#onError', function () {
it('uses the Error name when it is not just "Error"', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('TypeError');
});
@ -152,7 +150,7 @@ module.exports = function (makeLogger) {
it('uses "ERROR" when the error name is "Error"', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('ERROR');
});
@ -164,7 +162,7 @@ module.exports = function (makeLogger) {
describe('#onWarning', function () {
it('uses the "WARNING" label', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('WARNING');
});
logger.onWarning('message');
@ -185,7 +183,7 @@ module.exports = function (makeLogger) {
describe('#onInfo', function () {
it('uses the "INFO" label', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('INFO');
});
logger.onInfo('message');
@ -206,7 +204,7 @@ module.exports = function (makeLogger) {
describe('#onDebug', function () {
it('uses the "DEBUG" label', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('DEBUG');
});
logger.onDebug('message');
@ -227,7 +225,7 @@ module.exports = function (makeLogger) {
describe('#onTrace', function () {
it('uses the "TRACE" label', function () {
const logger = makeLogger();
stub(logger, 'write', function (label, msg) {
stub(logger, 'write', function (label) {
expect(label).to.eql('TRACE');
});
logger.onTrace(Log.normalizeTraceArgs('GET', 'http://place/thing?me=true', '{}', '{"ok": true}', 200));

View File

@ -1,11 +1,9 @@
describe('Logger Abstract', function () {
const expect = require('expect.js');
const sinon = require('sinon');
const Log = require('../../../src/lib/log');
const LoggerAbstract = require('../../../src/lib/logger');
let parentLog;
const 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 () {
const action = makeClientActionProxy(function (params, cb) {
const 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 () {
const action = makeClientActionProxy(function (params, cb) {
const 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 () {
const football = {};
const action = makeClientActionProxy(function (params, cb) {
const 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,11 @@ describe('Connection Abstract', function () {
it('requires a valid host', function () {
expect(function () {
const conn = new ConnectionAbstract();
new ConnectionAbstract();
}).to.throwError(TypeError);
expect(function () {
const conn = new ConnectionAbstract({});
new ConnectionAbstract({});
}).to.throwError(TypeError);
});

View File

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

View File

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

View File

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

View File

@ -3,15 +3,12 @@ describe('Http Connector', function () {
const _ = require('lodash');
const expect = require('expect.js');
const nock = require('nock');
const sinon = require('sinon');
const util = require('util');
const parseUrl = require('url').parse;
const http = require('http');
const https = require('https');
const AgentKeepAlive = require('agentkeepalive');
const Host = require('../../../src/lib/host');
const errors = require('../../../src/lib/errors');
const HttpConnection = require('../../../src/lib/connectors/http');
const ConnectionAbstract = require('../../../src/lib/connection');
@ -62,7 +59,7 @@ describe('Http Connector', function () {
it('expects the host to have a protocol of http or https', function () {
expect(function () {
const con = new HttpConnection(new Host('thrifty://es.com/stuff'));
new HttpConnection(new Host('thrifty://es.com/stuff'));
}).to.throwError(/invalid protocol/i);
});
@ -254,7 +251,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 +261,7 @@ describe('Http Connector', function () {
const 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 +272,7 @@ describe('Http Connector', function () {
const 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 +411,7 @@ describe('Http Connector', function () {
stub(http.ClientRequest.prototype, 'setNoDelay');
const 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 +430,7 @@ describe('Http Connector', function () {
con.request({
body: body
}, function (err, resp, status) {
}, function () {
expect(http.ClientRequest.prototype.setHeader.lastCall.args).to.eql(['Content-Length', 14]);
server.done();
done();
@ -449,7 +446,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();
@ -465,7 +462,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,22 @@ describe('Log class', function () {
it('rejects numbers and other truthy data-types', function () {
expect(function () {
const log = new Log({ log: 1515 });
new Log({ log: 1515 });
}).to.throwError(/invalid logging output config/i);
expect(function () {
const log = new Log({ log: /regexp/ });
new Log({ log: /regexp/ });
}).to.throwError(/invalid logging output config/i);
expect(function () {
const log = new Log({ log: new Date() });
new Log({ log: new Date() });
}).to.throwError(/invalid logging output config/i);
expect(function () {
const log = new Log({ log: [1515] });
new Log({ log: [1515] });
}).to.throwError(/invalid logging output config/i);
expect(function () {
const log = new Log({ log: [/regexp/] });
new Log({ log: [/regexp/] });
}).to.throwError(/invalid logging output config/i);
expect(function () {
const log = new Log({ log: [new Date()] });
new Log({ log: [new Date()] });
}).to.throwError(/invalid logging output config/i);
});
});

View File

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

View File

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

View File

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

View File

@ -59,7 +59,7 @@ describe('Transport Class', function () {
it('Throws an error when connectionPool config is set wrong', function () {
expect(function () {
const trans = new Transport({
new Transport({
connectionPool: 'pasta'
});
}).to.throwError(/invalid connectionpool/i);
@ -166,7 +166,7 @@ describe('Transport Class', function () {
describe('host config', function () {
it('rejects non-strings/objects', function () {
expect(function () {
const trans = new Transport({
new Transport({
host: [
'localhost',
9393
@ -175,7 +175,7 @@ describe('Transport Class', function () {
}).to.throwError(TypeError);
expect(function () {
const trans = new Transport({
new Transport({
host: [
[9292]
]
@ -288,7 +288,7 @@ describe('Transport Class', function () {
const _ = require('../../../src/lib/utils');
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
const trans = new Transport({
new Transport({
hosts: 'localhost'
});
@ -298,7 +298,7 @@ describe('Transport Class', function () {
const _ = require('../../../src/lib/utils');
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
const trans = new Transport({
new Transport({
hosts: 'localhost',
randomizeHosts: false
});

View File

@ -1,6 +1,5 @@
const Transport = require('../../../src/lib/transport');
const ConnectionPool = require('../../../src/lib/connection_pool');
const Host = require('../../../src/lib/host');
const errors = require('../../../src/lib/errors');
const expect = require('expect.js');
@ -10,21 +9,6 @@ const through2 = require('through2');
const _ = require('lodash');
const 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) {
const 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'
});
const 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'
});
const 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 () {
const clock = sinon.useFakeTimers('setTimeout');
stub.autoRelease(clock);
const serverMock = nock('http://esbox.1.com')
nock('http://esbox.1.com')
.get('/')
.reply(200, function () {
const 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);

View File

@ -40,9 +40,6 @@ function JenkinsReporter(runner) {
Base.call(this, runner);
const stats = this.stats;
let pass = 0;
let pending = 0;
let fail = 0;
const rootSuite = {
results: [],
suites: []
@ -94,14 +91,11 @@ function JenkinsReporter(runner) {
runner.on('test end', function (test) {
if (test.state === 'passed') {
pass++;
log(chalk.green('.'));
} else if (test.pending) {
pending++;
log(chalk.grey('.'));
return;
} else {
fail++;
log(chalk.red('x'));
}