Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Use const/let instead of var in all core plugins #6063

Merged
merged 10 commits into from
Feb 2, 2016
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rules:
no-bitwise: 0
no-caller: 2
no-cond-assign: 0
no-const-assign: 2
no-debugger: 2
no-empty: 2
no-eval: 2
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/devMode/public/ngMock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var angular = require('angular');
const angular = require('angular');
if (angular.mocks) {
throw new Error(
'Don\'t require angular-mocks directly or the tests ' +
Expand Down
30 changes: 15 additions & 15 deletions src/plugins/elasticsearch/lib/__tests__/check_es_version.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var _ = require('lodash');
var Promise = require('bluebird');
var sinon = require('sinon');
const _ = require('lodash');
const Promise = require('bluebird');
const sinon = require('sinon');

var checkEsVersion = require('../check_es_version');
const checkEsVersion = require('../check_es_version');

describe('plugins/elasticsearch', function () {
describe('lib/check_es_version', function () {
var server;
var plugin;
let server;
let plugin;

beforeEach(function () {
var get = sinon.stub().withArgs('elasticsearch.engineVersion').returns('^1.4.3');
var config = function () { return { get: get }; };
const get = sinon.stub().withArgs('elasticsearch.engineVersion').returns('^1.4.3');
const config = function () { return { get: get }; };
server = {
log: _.noop,
config: config,
Expand All @@ -30,15 +30,15 @@ describe('plugins/elasticsearch', function () {
});

function setNodes(/* ...versions */) {
var versions = _.shuffle(arguments);
var nodes = {};
var i = 0;
const versions = _.shuffle(arguments);
const nodes = {};
let i = 0;

while (versions.length) {
var name = 'node-' + (++i);
var version = versions.shift();
const name = 'node-' + (++i);
const version = versions.shift();

var node = {
const node = {
version: version,
http_address: 'http_address',
ip: 'ip'
Expand All @@ -48,7 +48,7 @@ describe('plugins/elasticsearch', function () {
nodes[name] = node;
}

var client = server.plugins.elasticsearch.client;
const client = server.plugins.elasticsearch.client;
client.nodes.info = sinon.stub().returns(Promise.resolve({ nodes: nodes }));

}
Expand Down
46 changes: 23 additions & 23 deletions src/plugins/elasticsearch/lib/__tests__/create_kibana_index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var _ = require('lodash');
var sinon = require('sinon');
var expect = require('expect.js');
var Promise = require('bluebird');
const _ = require('lodash');
const sinon = require('sinon');
const expect = require('expect.js');
const Promise = require('bluebird');

var createKibanaIndex = require('../create_kibana_index');
var SetupError = require('../setup_error');
const createKibanaIndex = require('../create_kibana_index');
const SetupError = require('../setup_error');

describe('plugins/elasticsearch', function () {
describe('lib/create_kibana_index', function () {

var server;
var client;
let server;
let client;
beforeEach(function () {
server = {};
client = {};
var config = { kibana: { index: '.my-kibana' } };
var get = sinon.stub();
let config = { kibana: { index: '.my-kibana' } };
const get = sinon.stub();
get.returns(config);
get.withArgs('kibana.index').returns(config.kibana.index);
config = function () { return { get: get }; };
Expand All @@ -33,16 +33,16 @@ describe('plugins/elasticsearch', function () {
});

it('should check cluster.health upon successful index creation', function () {
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.then(function () {
sinon.assert.calledOnce(client.cluster.health);
});
});

it('should be created with mappings for config.buildNum', function () {
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.then(function () {
var params = client.indices.create.args[0][0];
const params = client.indices.create.args[0][0];
expect(params)
.to.have.property('body');
expect(params.body)
Expand All @@ -61,9 +61,9 @@ describe('plugins/elasticsearch', function () {
});

it('should be created with 1 shard and default replica', function () {
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.then(function () {
var params = client.indices.create.args[0][0];
const params = client.indices.create.args[0][0];
expect(params)
.to.have.property('body');
expect(params.body)
Expand All @@ -76,9 +76,9 @@ describe('plugins/elasticsearch', function () {
});

it('should be created with index name set in the config', function () {
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.then(function () {
var params = client.indices.create.args[0][0];
const params = client.indices.create.args[0][0];
expect(params)
.to.have.property('index', '.my-kibana');
});
Expand All @@ -89,18 +89,18 @@ describe('plugins/elasticsearch', function () {

describe('failure requests', function () {
it('should reject with a SetupError', function () {
var error = new Error('Oops!');
const error = new Error('Oops!');
client.indices.create.returns(Promise.reject(error));
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.catch(function (err) {
expect(err).to.be.a(SetupError);
});
});

it('should reject with an error if index creation fails', function () {
var error = new Error('Oops!');
const error = new Error('Oops!');
client.indices.create.returns(Promise.reject(error));
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.catch(function (err) {
expect(err.message).to.be('Unable to create Kibana index ".my-kibana"');
expect(err).to.have.property('origError', error);
Expand All @@ -109,10 +109,10 @@ describe('plugins/elasticsearch', function () {


it('should reject with an error if health check fails', function () {
var error = new Error('Oops!');
const error = new Error('Oops!');
client.indices.create.returns(Promise.resolve());
client.cluster.health.returns(Promise.reject(error));
var fn = createKibanaIndex(server);
const fn = createKibanaIndex(server);
return fn.catch(function (err) {
expect(err.message).to.be('Waiting for Kibana index ".my-kibana" to come online failed.');
expect(err).to.have.property('origError', error);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/elasticsearch/lib/__tests__/findPort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Promise = require('bluebird');
var portscanner = require('portscanner');
const Promise = require('bluebird');
const portscanner = require('portscanner');

module.exports = function findPort(start, end, host) {
host = host || 'localhost';
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/elasticsearch/lib/__tests__/health_check.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var Promise = require('bluebird');
var sinon = require('sinon');
var expect = require('expect.js');
var NoConnections = require('elasticsearch').errors.NoConnections;
const Promise = require('bluebird');
const sinon = require('sinon');
const expect = require('expect.js');
const NoConnections = require('elasticsearch').errors.NoConnections;

var healthCheck = require('../health_check');
const healthCheck = require('../health_check');

describe('plugins/elasticsearch', function () {
describe('lib/health_check', function () {

var health;
var plugin;
var server;
var get;
var client;
let health;
let plugin;
let server;
let get;
let client;

beforeEach(function () {
// setup the plugin stub
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/elasticsearch/lib/__tests__/routes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var expect = require('expect.js');
var util = require('util');
var requireFromTest = require('requirefrom')('test');
var kbnTestServer = requireFromTest('utils/kbn_server');
const expect = require('expect.js');
const util = require('util');
const requireFromTest = require('requirefrom')('test');
const kbnTestServer = requireFromTest('utils/kbn_server');

var format = util.format;
const format = util.format;


describe('plugins/elasticsearch', function () {
describe('routes', function () {

var kbnServer;
let kbnServer;

before(function () {
kbnServer = kbnTestServer.createServer();
Expand All @@ -28,7 +28,7 @@ describe('plugins/elasticsearch', function () {
options.payload = JSON.stringify(options.payload);
}

var statusCode = options.statusCode || 200;
const statusCode = options.statusCode || 200;
describe(format('%s %s', options.method, options.url), function () {
it('should should return ' + statusCode, function (done) {
kbnTestServer.makeRequest(kbnServer, options, function (res) {
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/elasticsearch/lib/__tests__/setup_error.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var SetupError = require('../setup_error');
var expect = require('expect.js');
const SetupError = require('../setup_error');
const expect = require('expect.js');

describe('plugins/elasticsearch', function () {
describe('lib/setup_error', function () {

var server = {
const server = {
config: function () {
return {
get: function () {
Expand All @@ -14,7 +14,7 @@ describe('plugins/elasticsearch', function () {
}
};

var err = new SetupError(server, 'Oops! <%= kibana.index %>');
const err = new SetupError(server, 'Oops! <%= kibana.index %>');

it('should allow config values in the message template', function () {
expect(err).to.have.property('message', 'Oops! .my-kibana');
Expand All @@ -30,19 +30,19 @@ describe('plugins/elasticsearch', function () {
});

it('should return the passed error if it is a SetupError', function () {
var error = new SetupError(server, 'Oh Boy!', err);
const error = new SetupError(server, 'Oh Boy!', err);
expect(error).to.have.property('message', 'Oops! .my-kibana');
});

it('should store the original error', function () {
var origError = new Error('Boom!');
var error = new SetupError(server, 'Oh Boy!', origError);
const origError = new Error('Boom!');
const error = new SetupError(server, 'Oh Boy!', origError);
expect(error).to.have.property('origError', origError);
});

it('should copy the stack from the origError', function () {
var origError = new Error('Boom!');
var error = new SetupError(server, 'Oh Boy!', origError);
const origError = new Error('Boom!');
const error = new SetupError(server, 'Oh Boy!', origError);
expect(error).to.have.property('stack', origError.stack);
});

Expand Down
Loading