Skip to content
This repository was archived by the owner on Mar 31, 2024. It is now read-only.

re-enable and autofix prefer-const rule #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
extends: '@elastic/kibana'
rules:
no-unused-vars: off
prefer-const: off
no-extra-semi: off
quotes: off
14 changes: 7 additions & 7 deletions src/cli/cluster/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { EventEmitter } from 'events';

import { BinderFor, fromRoot } from '../../utils';

let cliPath = fromRoot('src/cli');
let baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
let baseArgv = [process.execPath, cliPath].concat(baseArgs);
const cliPath = fromRoot('src/cli');
const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']);
const baseArgv = [process.execPath, cliPath].concat(baseArgs);

cluster.setupMaster({
exec: cliPath,
silent: false
});

let dead = fork => {
const dead = fork => {
return fork.isDead() || fork.killed;
};

Expand All @@ -40,7 +40,7 @@ module.exports = class Worker extends EventEmitter {
this.clusterBinder = new BinderFor(cluster);
this.processBinder = new BinderFor(process);

let argv = _.union(baseArgv, opts.argv || []);
const argv = _.union(baseArgv, opts.argv || []);
this.env = {
kbnWorkerType: this.type,
kbnWorkerArgv: JSON.stringify(argv)
Expand Down Expand Up @@ -124,8 +124,8 @@ module.exports = class Worker extends EventEmitter {
}

flushChangeBuffer() {
let files = _.unique(this.changes.splice(0));
let prefix = files.length > 1 ? '\n - ' : '';
const files = _.unique(this.changes.splice(0));
const prefix = files.length > 1 ? '\n - ' : '';
return files.reduce(function (list, file) {
return `${list || ''}${prefix}"${file}"`;
}, '');
Expand Down
12 changes: 6 additions & 6 deletions src/cli/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ Command.prototype.unknownArgv = function (argv) {
* @return {[type]} [description]
*/
Command.prototype.collectUnknownOptions = function () {
let title = `Extra ${this._name} options`;
const title = `Extra ${this._name} options`;

this.allowUnknownOption();
this.getUnknownOptions = function () {
let opts = {};
let unknowns = this.unknownArgv();
const opts = {};
const unknowns = this.unknownArgv();

while (unknowns.length) {
let opt = unknowns.shift().split('=');
const opt = unknowns.shift().split('=');
if (opt[0].slice(0, 2) !== '--') {
this.error(`${title} "${opt[0]}" must start with "--"`);
}
Expand All @@ -75,14 +75,14 @@ Command.prototype.collectUnknownOptions = function () {
};

Command.prototype.parseOptions = _.wrap(Command.prototype.parseOptions, function (parse, argv) {
let opts = parse.call(this, argv);
const opts = parse.call(this, argv);
this.unknownArgv(opts.unknown);
return opts;
});

Command.prototype.action = _.wrap(Command.prototype.action, function (action, fn) {
return action.call(this, function (...args) {
let ret = fn.apply(this, args);
const ret = fn.apply(this, args);
if (ret && typeof ret.then === 'function') {
ret.then(null, function (e) {
console.log('FATAL CLI ERROR', e.stack);
Expand Down
18 changes: 9 additions & 9 deletions src/cli/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = function (command, spaces) {
return command.outputHelp();
}

let defCmd = _.find(command.commands, function (cmd) {
const defCmd = _.find(command.commands, function (cmd) {
return cmd._name === 'serve';
});

let desc = !command.description() ? '' : command.description();
let cmdDef = !defCmd ? '' : `=${defCmd._name}`;
const desc = !command.description() ? '' : command.description();
const cmdDef = !defCmd ? '' : `=${defCmd._name}`;

return (
`
Expand All @@ -31,11 +31,11 @@ function indent(str, n) {
}

function commandsSummary(program) {
let cmds = _.compact(program.commands.map(function (cmd) {
let name = cmd._name;
const cmds = _.compact(program.commands.map(function (cmd) {
const name = cmd._name;
if (name === '*') return;
let opts = cmd.options.length ? ' [options]' : '';
let args = cmd._args.map(function (arg) {
const opts = cmd.options.length ? ' [options]' : '';
const args = cmd._args.map(function (arg) {
return humanReadableArgName(arg);
}).join(' ');

Expand All @@ -45,7 +45,7 @@ function commandsSummary(program) {
];
}));

let cmdLColWidth = cmds.reduce(function (width, cmd) {
const cmdLColWidth = cmds.reduce(function (width, cmd) {
return Math.max(width, cmd[0].length);
}, 0);

Expand All @@ -69,6 +69,6 @@ ${indent(cmd.optionHelp(), 2)}
}

function humanReadableArgName(arg) {
let nameOutput = arg.name + (arg.variadic === true ? '...' : '');
const nameOutput = arg.name + (arg.variadic === true ? '...' : '');
return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
}
2 changes: 1 addition & 1 deletion src/cli/log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import ansicolors from 'ansicolors';

let log = _.restParam(function (color, label, rest1) {
const log = _.restParam(function (color, label, rest1) {
console.log.apply(console, [color(` ${_.trim(label)} `)].concat(rest1));
});

Expand Down
8 changes: 4 additions & 4 deletions src/cli_plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import listCommand from './list';
import installCommand from './install';
import removeCommand from './remove';

let argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
let program = new Command('bin/kibana-plugin');
const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
const program = new Command('bin/kibana-plugin');

program
.version(pkg.version)
Expand All @@ -23,7 +23,7 @@ program
.command('help <command>')
.description('get the help for a specific command')
.action(function (cmdName) {
let cmd = _.find(program.commands, { _name: cmdName });
const cmd = _.find(program.commands, { _name: cmdName });
if (!cmd) return program.error(`unknown command ${cmdName}`);
cmd.help();
});
Expand All @@ -35,7 +35,7 @@ program
});

// check for no command name
let subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
const subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
if (!subCommand) {
program.defaultHelp();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('kibana cli', function () {

describe('commander options', function () {

let program = {
const program = {
command: function () { return program; },
description: function () { return program; },
option: function () { return program; },
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/downloaders/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createWriteStream, createReadStream, unlinkSync, statSync } from 'fs';

function openSourceFile({ sourcePath }) {
try {
let fileInfo = statSync(sourcePath);
const fileInfo = statSync(sourcePath);

const readStream = createReadStream(sourcePath);

Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/downloaders/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function downloadUrl(logger, sourceUrl, targetPath, timeout
const { req, resp } = await sendRequest({ sourceUrl, timeout });

try {
let totalSize = parseFloat(resp.headers['content-length']) || 0;
const totalSize = parseFloat(resp.headers['content-length']) || 0;
const progress = new Progress(logger);
progress.init(totalSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let version = pkg.version;

describe('plugins/elasticsearch', function () {
describe('lib/is_upgradeable', function () {
let server = {
const server = {
config: _.constant({
get: function (key) {
switch (key) {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('plugins/elasticsearch', function () {
upgradeDoc('5.0.0-alpha1', '5.0.0', false);

it('should handle missing _id field', function () {
let doc = {
const doc = {
'_index': '.kibana',
'_type': 'config',
'_score': 1,
Expand All @@ -58,7 +58,7 @@ describe('plugins/elasticsearch', function () {
});

it('should handle _id of @@version', function () {
let doc = {
const doc = {
'_index': '.kibana',
'_type': 'config',
'_id': '@@version',
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/kbn_doc_views/public/views/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ docViewsRegistry.register(function () {
};

$scope.showArrayInObjectsWarning = function (row, field) {
let value = $scope.flattened[field];
const value = $scope.flattened[field];
return _.isArray(value) && typeof value[0] === 'object';
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (kibana) {
],

injectVars: function (server, options) {
let config = server.config();
const config = server.config();
return {
kbnDefaultAppId: config.get('kibana.defaultAppId'),
tilemap: config.get('tilemap')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ app.directive('outputPreview', function () {
});

$scope.updateUi = function () {
let left = $scope.oldObject;
let right = $scope.newObject;
const left = $scope.oldObject;
const right = $scope.newObject;
let delta = $scope.diffpatch.diff(left, right);
if (!delta || $scope.error) delta = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import keysDeep from '../keys_deep';
describe('keys deep', function () {

it('should list first level properties', function () {
let object = {
const object = {
property1: 'value1',
property2: 'value2'
};
let expected = [
const expected = [
'property1',
'property2'
];
Expand All @@ -20,14 +20,14 @@ describe('keys deep', function () {
});

it('should list nested properties', function () {
let object = {
const object = {
property1: 'value1',
property2: 'value2',
property3: {
subProperty1: 'value1.1'
}
};
let expected = [
const expected = [
'property1',
'property2',
'property3.subProperty1',
Expand All @@ -40,7 +40,7 @@ describe('keys deep', function () {
});

it('should recursivly list nested properties', function () {
let object = {
const object = {
property1: 'value1',
property2: 'value2',
property3: {
Expand All @@ -52,7 +52,7 @@ describe('keys deep', function () {
subProperty3: 'value1.3'
}
};
let expected = [
const expected = [
'property1',
'property2',
'property3.subProperty1',
Expand All @@ -69,11 +69,11 @@ describe('keys deep', function () {
});

it('should list array properties, but not contents', function () {
let object = {
const object = {
property1: 'value1',
property2: [ 'item1', 'item2' ]
};
let expected = [
const expected = [
'property1',
'property2'
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import _ from 'lodash';

export default function keysDeep(object, base) {
let result = [];
let delimitedBase = base ? base + '.' : '';
const delimitedBase = base ? base + '.' : '';

_.forEach(object, (value, key) => {
let fullKey = delimitedBase + key;
const fullKey = delimitedBase + key;
if (_.isPlainObject(value)) {
result = result.concat(keysDeep(value, fullKey));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ modules.get('apps/management')
const ingest = Private(IngestProvider);
const $state = this.state = new AppState();

let notify = new Notifier({
const notify = new Notifier({
location: 'Add Data'
});

let totalSteps = 4;
const totalSteps = 4;
this.stepResults = {};

this.setCurrentStep = (step) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ modules.get('apps/management')
const ingest = Private(IngestProvider);
const $state = this.state = new AppState();

let notify = new Notifier({
const notify = new Notifier({
location: 'Add Data'
});

let totalSteps = 3;
const totalSteps = 3;
this.stepResults = {};

this.setCurrentStep = (step) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('createMappingsFromPatternFields', function () {
});

it('should set the same default mapping for all non-strings', function () {
let mappings = createMappingsFromPatternFields(testFields);
const mappings = createMappingsFromPatternFields(testFields);

_.forEach(mappings, function (mapping) {
if (mapping.type !== 'text') {
Expand All @@ -50,7 +50,7 @@ describe('createMappingsFromPatternFields', function () {
});

it('should give strings a multi-field mapping with a "text" base type', function () {
let mappings = createMappingsFromPatternFields(testFields);
const mappings = createMappingsFromPatternFields(testFields);

_.forEach(mappings, function (mapping) {
if (mapping.type === 'text') {
Expand All @@ -61,7 +61,7 @@ describe('createMappingsFromPatternFields', function () {

it('should handle nested fields', function () {
testFields.push({name: 'geo.coordinates', type: 'geo_point'});
let mappings = createMappingsFromPatternFields(testFields);
const mappings = createMappingsFromPatternFields(testFields);

expect(mappings).to.have.property('geo');
expect(mappings.geo).to.have.property('properties');
Expand All @@ -74,7 +74,7 @@ describe('createMappingsFromPatternFields', function () {
});

it('should map all number fields as an ES double', function () {
let mappings = createMappingsFromPatternFields(testFields);
const mappings = createMappingsFromPatternFields(testFields);

expect(mappings).to.have.property('bytes');
expect(mappings.bytes).to.have.property('type', 'double');
Expand Down
Loading