[internal] Replace let with const in root of ui

This change was applied only to files in the root of the src/ui
directory.

All instances of `let` were replaced with `const`, and then any instance
that flagged the `no-const-assign` rule in the linter was put back.
This commit is contained in:
Court Ewing 2016-04-12 17:55:25 -04:00
parent a6ed127564
commit 31a1e1aa7c
7 changed files with 42 additions and 42 deletions

View file

@ -1,10 +1,10 @@
module.exports = function ({env, bundle}) {
let pluginSlug = env.pluginInfo.sort()
const pluginSlug = env.pluginInfo.sort()
.map(p => ' * - ' + p)
.join('\n');
let requires = bundle.modules
const requires = bundle.modules
.map(m => `require('${m}');`)
.join('\n');

View file

@ -10,13 +10,13 @@ import UiBundleCollection from './ui_bundle_collection';
import UiBundlerEnv from './ui_bundler_env';
module.exports = async (kbnServer, server, config) => {
let loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'});
const loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'});
let uiExports = kbnServer.uiExports = new UiExports({
const uiExports = kbnServer.uiExports = new UiExports({
urlBasePath: config.get('server.basePath')
});
let bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir'));
const bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir'));
bundlerEnv.addContext('env', config.get('env.name'));
bundlerEnv.addContext('urlBasePath', config.get('server.basePath'));
bundlerEnv.addContext('sourceMaps', config.get('optimize.sourceMaps'));
@ -28,14 +28,14 @@ module.exports = async (kbnServer, server, config) => {
uiExports.consumePlugin(plugin);
}
let bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter'));
const bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter'));
for (let app of uiExports.getAllApps()) {
bundles.addApp(app);
}
for (let gen of uiExports.getBundleProviders()) {
let bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps(), kbnServer.plugins);
const bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps(), kbnServer.plugins);
if (bundle) bundles.add(bundle);
}
@ -47,8 +47,8 @@ module.exports = async (kbnServer, server, config) => {
path: '/app/{id}',
method: 'GET',
handler: function (req, reply) {
let id = req.params.id;
let app = uiExports.apps.byId[id];
const id = req.params.id;
const app = uiExports.apps.byId[id];
if (!app) return reply(Boom.notFound('Unknown app ' + id));
if (kbnServer.status.isGreen()) {

View file

@ -2,7 +2,7 @@ import _ from 'lodash';
import UiApp from './ui_app';
import Collection from '../utils/collection';
let byIdCache = Symbol('byId');
const byIdCache = Symbol('byId');
module.exports = class UiAppCollection extends Collection {
@ -25,7 +25,7 @@ module.exports = class UiAppCollection extends Collection {
return this.hidden.new(spec);
}
let app = new UiApp(this.uiExports, spec);
const app = new UiApp(this.uiExports, spec);
if (_.includes(this.claimedIds, app.id)) {
throw new Error('Unable to create two apps with the id ' + app.id + '.');

View file

@ -1,10 +1,10 @@
import { join } from 'path';
import { promisify } from 'bluebird';
let read = promisify(require('fs').readFile);
let write = promisify(require('fs').writeFile);
let unlink = promisify(require('fs').unlink);
let stat = promisify(require('fs').stat);
const read = promisify(require('fs').readFile);
const write = promisify(require('fs').writeFile);
const unlink = promisify(require('fs').unlink);
const stat = promisify(require('fs').stat);
module.exports = class UiBundle {
constructor(opts) {
@ -15,7 +15,7 @@ module.exports = class UiBundle {
this.template = opts.template;
this.env = opts.env;
let pathBase = join(this.env.workingDir, this.id);
const pathBase = join(this.env.workingDir, this.id);
this.entryPath = `${pathBase}.entry.js`;
this.outputPath = `${pathBase}.bundle.js`;
@ -30,7 +30,7 @@ module.exports = class UiBundle {
async readEntryFile() {
try {
let content = await read(this.entryPath);
const content = await read(this.entryPath);
return content.toString('utf8');
}
catch (e) {

View file

@ -1,7 +1,7 @@
let rimraf = promisify(require('rimraf'));
let mkdirp = promisify(require('mkdirp'));
let unlink = promisify(require('fs').unlink);
let readdir = promisify(require('fs').readdir);
const rimraf = promisify(require('rimraf'));
const mkdirp = promisify(require('mkdirp'));
const unlink = promisify(require('fs').unlink);
const readdir = promisify(require('fs').readdir);
import UiBundle from './ui_bundle';
import appEntryTemplate from './app_entry_template';
@ -48,9 +48,9 @@ class UiBundleCollection {
case 1:
return `bundle for ${this.each[0].id}`;
default:
let ids = this.getIds();
let last = ids.pop();
let commas = ids.join(', ');
const ids = this.getIds();
const last = ids.pop();
const commas = ids.join(', ');
return `bundles for ${commas} and ${last}`;
}
}
@ -63,8 +63,8 @@ class UiBundleCollection {
await this.ensureDir();
for (let bundle of this.each) {
let existing = await bundle.readEntryFile();
let expected = bundle.renderContent();
const existing = await bundle.readEntryFile();
const expected = bundle.renderContent();
if (existing !== expected) {
await bundle.writeEntryFile();
@ -74,10 +74,10 @@ class UiBundleCollection {
}
async getInvalidBundles() {
let invalids = new UiBundleCollection(this.env);
const invalids = new UiBundleCollection(this.env);
for (let bundle of this.each) {
let exists = await bundle.checkForExistingOutput();
const exists = await bundle.checkForExistingOutput();
if (!exists) {
invalids.add(bundle);
}

View file

@ -3,10 +3,10 @@ import { includes, flow, escapeRegExp } from 'lodash';
import { isString, isArray, isPlainObject, get } from 'lodash';
import { keys } from 'lodash';
let asRegExp = flow(
const asRegExp = flow(
escapeRegExp,
function (path) {
let last = path.slice(-1);
const last = path.slice(-1);
if (last === '/' || last === '\\') {
// match a directory explicitly
return path + '.*';
@ -18,7 +18,7 @@ let asRegExp = flow(
RegExp
);
let arr = v => [].concat(v || []);
const arr = v => [].concat(v || []);
module.exports = class UiBundlerEnv {
constructor(workingDir) {
@ -58,7 +58,7 @@ module.exports = class UiBundlerEnv {
}
consumePlugin(plugin) {
let tag = `${plugin.id}@${plugin.version}`;
const tag = `${plugin.id}@${plugin.version}`;
if (includes(this.pluginInfo, tag)) return;
if (plugin.publicDir) {
@ -141,7 +141,7 @@ module.exports = class UiBundlerEnv {
this.aliases[id] = path;
let loader = [];
const loader = [];
if (imports) {
loader.push(`imports?${imports}`);
}
@ -153,10 +153,10 @@ module.exports = class UiBundlerEnv {
}
claim(id, pluginId) {
let owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server';
const owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server';
// TODO(spalger): we could do a lot more to detect colliding module defs
let existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];
const existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];
if (existingOwner) {
throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`);

View file

@ -19,10 +19,10 @@ class UiExports {
consumePlugin(plugin) {
plugin.apps = new UiAppCollection(this);
let types = _.keys(plugin.uiExportsSpecs);
const types = _.keys(plugin.uiExportsSpecs);
if (!types) return false;
let unkown = _.reject(types, this.exportConsumer, this);
const unkown = _.reject(types, this.exportConsumer, this);
if (unkown.length) {
throw new Error('unknown export types ' + unkown.join(', ') + ' in plugin ' + plugin.id);
}
@ -43,7 +43,7 @@ class UiExports {
exportConsumer(type) {
for (let consumer of this.consumers) {
if (!consumer.exportConsumer) continue;
let fn = consumer.exportConsumer(type);
const fn = consumer.exportConsumer(type);
if (fn) return fn;
}
@ -54,7 +54,7 @@ class UiExports {
const id = plugin.id;
for (let spec of [].concat(specs || [])) {
let app = this.apps.new(_.defaults({}, spec, {
const app = this.apps.new(_.defaults({}, spec, {
id: plugin.id,
urlBasePath: this.urlBasePath
}));
@ -110,9 +110,9 @@ class UiExports {
}
find(patterns) {
let aliases = this.aliases;
let names = _.keys(aliases);
let matcher = _.partialRight(minimatch.filter, { matchBase: true });
const aliases = this.aliases;
const names = _.keys(aliases);
const matcher = _.partialRight(minimatch.filter, { matchBase: true });
return _.chain(patterns)
.map(function (pattern) {