From 01039f854f722210584ea3565592fa1fd89e7b3c Mon Sep 17 00:00:00 2001 From: jasper Date: Mon, 26 Dec 2016 20:43:55 -0500 Subject: [PATCH] console: clean up styles for entry and server code (#9648) Backports PR #9646 **Commit 1:** console: clean up styles for entry and server code Much of the code in console is original from when the project was a separate plugin and was not updated when it was ported over. Now, any code in the root of the project or in the server directory will be linted based on the global rules in Kibana. * Original sha: aa82918c401cb4544e68f9e2bc350f2fc6cdf9d0 * Authored by Court Ewing on 2016-12-26T20:02:30Z --- .../console/{ => api_server}/.eslintrc | 2 +- src/core_plugins/console/index.js | 34 +++++++++--------- src/core_plugins/console/public/.eslintrc | 36 +++++++++++++++++++ .../console/server/__tests__/proxy_config.js | 6 ++-- .../__tests__/proxy_config_collection.js | 6 ++-- .../server/__tests__/wildcard_matcher.js | 4 +-- .../console/server/proxy_config.js | 12 +++---- .../console/server/proxy_config_collection.js | 8 ++--- .../console/server/wildcard_matcher.js | 6 ++-- 9 files changed, 75 insertions(+), 39 deletions(-) rename src/core_plugins/console/{ => api_server}/.eslintrc (94%) create mode 100644 src/core_plugins/console/public/.eslintrc diff --git a/src/core_plugins/console/.eslintrc b/src/core_plugins/console/api_server/.eslintrc similarity index 94% rename from src/core_plugins/console/.eslintrc rename to src/core_plugins/console/api_server/.eslintrc index f539f6cd5878f..86a66ca21d420 100644 --- a/src/core_plugins/console/.eslintrc +++ b/src/core_plugins/console/api_server/.eslintrc @@ -1,7 +1,7 @@ --- root: true -extends: '../../../.eslintrc' +extends: '../../../../.eslintrc' rules: block-scoped-var: off diff --git a/src/core_plugins/console/index.js b/src/core_plugins/console/index.js index 3f1438ee915f5..a5d0865791fb8 100644 --- a/src/core_plugins/console/index.js +++ b/src/core_plugins/console/index.js @@ -1,13 +1,14 @@ +import Joi from 'joi'; +import Boom from 'boom'; +import apiServer from './api_server/server'; +import { existsSync } from 'fs'; +import { resolve, join, sep } from 'path'; +import { startsWith, endsWith } from 'lodash'; import { ProxyConfigCollection } from './server/proxy_config_collection'; -module.exports = function (kibana) { - let { resolve, join, sep } = require('path'); - let Joi = require('joi'); - let Boom = require('boom'); - let modules = resolve(__dirname, 'public/webpackShims/'); - let src = resolve(__dirname, 'public/src/'); - let { existsSync } = require('fs'); - const { startsWith, endsWith } = require('lodash'); +export default function (kibana) { + const modules = resolve(__dirname, 'public/webpackShims/'); + const src = resolve(__dirname, 'public/src/'); const apps = []; @@ -88,7 +89,7 @@ module.exports = function (kibana) { if (!filters.some(re => re.test(uri))) { const err = Boom.forbidden(); - err.output.payload = "Error connecting to '" + uri + "':\n\nUnable to send requests to that url."; + err.output.payload = `Error connecting to '${uri}':\n\nUnable to send requests to that url.`; err.output.headers['content-type'] = 'text/plain'; reply(err); } else { @@ -109,19 +110,19 @@ module.exports = function (kibana) { const filterHeaders = server.plugins.elasticsearch.filterHeaders; reply.proxy({ mapUri: function (request, done) { - done(null, uri, filterHeaders(request.headers, requestHeadersWhitelist)) + done(null, uri, filterHeaders(request.headers, requestHeadersWhitelist)); }, xforward: true, onResponse(err, res, request, reply, settings, ttl) { if (err != null) { - reply("Error connecting to '" + uri + "':\n\n" + err.message).type("text/plain").statusCode = 502; + reply(`Error connecting to '${uri}':\n\n${err.message}`).type('text/plain').statusCode = 502; } else { reply(null, res); } }, ...proxyConfigCollection.configForUri(uri) - }) + }); } }; @@ -150,14 +151,13 @@ module.exports = function (kibana) { path: '/api/console/api_server', method: ['GET', 'POST'], handler: function (req, reply) { - let server = require('./api_server/server'); - let {sense_version, apis} = req.query; + const { sense_version, apis } = req.query; if (!apis) { reply(Boom.badRequest('"apis" is a required param.')); return; } - return server.resolveApi(sense_version, apis.split(","), reply); + return apiServer.resolveApi(sense_version, apis.split(','), reply); } }); @@ -190,5 +190,5 @@ module.exports = function (kibana) { join(src, 'sense_editor/mode/worker.js') ] } - }) -}; + }); +} diff --git a/src/core_plugins/console/public/.eslintrc b/src/core_plugins/console/public/.eslintrc new file mode 100644 index 0000000000000..86a66ca21d420 --- /dev/null +++ b/src/core_plugins/console/public/.eslintrc @@ -0,0 +1,36 @@ +--- + +root: true +extends: '../../../../.eslintrc' + +rules: + block-scoped-var: off + camelcase: off + curly: off + dot-location: off + dot-notation: off + eqeqeq: off + guard-for-in: off + indent: off + max-len: off + new-cap: off + no-caller: off + no-empty: off + no-extend-native: off + no-loop-func: off + no-multi-str: off + no-nested-ternary: off + no-proto: off + no-sequences: off + no-undef: off + no-use-before-define: off + one-var: off + quotes: off + space-before-blocks: off + space-in-parens: off + space-infix-ops: off + semi: off + strict: off + wrap-iife: off + no-var: off + prefer-const: off diff --git a/src/core_plugins/console/server/__tests__/proxy_config.js b/src/core_plugins/console/server/__tests__/proxy_config.js index 301e9a12a9020..6314fb37a7a32 100644 --- a/src/core_plugins/console/server/__tests__/proxy_config.js +++ b/src/core_plugins/console/server/__tests__/proxy_config.js @@ -6,20 +6,20 @@ import fs from 'fs'; import https, { Agent as HttpsAgent } from 'https'; import { parse as parseUrl } from 'url'; -import { ProxyConfig } from '../proxy_config' +import { ProxyConfig } from '../proxy_config'; const matchGoogle = { protocol: 'https', host: 'google.com', path: '/search' -} +}; const parsedGoogle = parseUrl('https://google.com/search'); const parsedLocalEs = parseUrl('https://localhost:5601/search'); describe('ProxyConfig', function () { beforeEach(function () { sinon.stub(fs, 'readFileSync', function (path) { - return { path } + return { path }; }); }); diff --git a/src/core_plugins/console/server/__tests__/proxy_config_collection.js b/src/core_plugins/console/server/__tests__/proxy_config_collection.js index 9e9ce19c51787..ad1717ae0e5b7 100644 --- a/src/core_plugins/console/server/__tests__/proxy_config_collection.js +++ b/src/core_plugins/console/server/__tests__/proxy_config_collection.js @@ -5,7 +5,7 @@ import sinon from 'sinon'; import fs from 'fs'; import { Agent as HttpsAgent } from 'https'; -import { ProxyConfigCollection } from '../proxy_config_collection' +import { ProxyConfigCollection } from '../proxy_config_collection'; describe('ProxyConfigCollection', function () { beforeEach(function () { @@ -60,7 +60,7 @@ describe('ProxyConfigCollection', function () { timeout: 5 } - ] + ]; function getTimeout(uri) { const collection = new ProxyConfigCollection(proxyConfigs); @@ -69,7 +69,7 @@ describe('ProxyConfigCollection', function () { context('http://localhost:5601', function () { it('defaults to the first matching timeout', function () { - expect(getTimeout('http://localhost:5601')).to.be(3) + expect(getTimeout('http://localhost:5601')).to.be(3); }); }); diff --git a/src/core_plugins/console/server/__tests__/wildcard_matcher.js b/src/core_plugins/console/server/__tests__/wildcard_matcher.js index 8ef3131891a83..c60ac51c21e4d 100644 --- a/src/core_plugins/console/server/__tests__/wildcard_matcher.js +++ b/src/core_plugins/console/server/__tests__/wildcard_matcher.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import expect from 'expect.js' +import expect from 'expect.js'; -import { WildcardMatcher } from '../wildcard_matcher' +import { WildcardMatcher } from '../wildcard_matcher'; function should(candidate, ...constructorArgs) { if (!new WildcardMatcher(...constructorArgs).match(candidate)) { diff --git a/src/core_plugins/console/server/proxy_config.js b/src/core_plugins/console/server/proxy_config.js index 455784df2d125..70d76aa75b88c 100644 --- a/src/core_plugins/console/server/proxy_config.js +++ b/src/core_plugins/console/server/proxy_config.js @@ -1,14 +1,14 @@ -import { memoize, values } from 'lodash' -import { format as formatUrl } from 'url' -import { Agent as HttpsAgent } from 'https' -import { readFileSync } from 'fs' +import { memoize, values } from 'lodash'; +import { format as formatUrl } from 'url'; +import { Agent as HttpsAgent } from 'https'; +import { readFileSync } from 'fs'; -import { WildcardMatcher } from './wildcard_matcher' +import { WildcardMatcher } from './wildcard_matcher'; const makeHttpsAgent = memoize( opts => new HttpsAgent(opts), opts => JSON.stringify(opts) -) +); export class ProxyConfig { constructor(config) { diff --git a/src/core_plugins/console/server/proxy_config_collection.js b/src/core_plugins/console/server/proxy_config_collection.js index cb027bc0fe897..5d19034f46e58 100644 --- a/src/core_plugins/console/server/proxy_config_collection.js +++ b/src/core_plugins/console/server/proxy_config_collection.js @@ -1,12 +1,12 @@ -import { defaultsDeep } from 'lodash' +import { defaultsDeep } from 'lodash'; -import { ProxyConfig } from './proxy_config' -import { parse as parseUrl } from 'url' +import { ProxyConfig } from './proxy_config'; +import { parse as parseUrl } from 'url'; export class ProxyConfigCollection { constructor(configs = []) { - this.configs = configs.map(settings => new ProxyConfig(settings)) + this.configs = configs.map(settings => new ProxyConfig(settings)); } configForUri(uri) { diff --git a/src/core_plugins/console/server/wildcard_matcher.js b/src/core_plugins/console/server/wildcard_matcher.js index d25e018f12f05..b37d74f04246f 100644 --- a/src/core_plugins/console/server/wildcard_matcher.js +++ b/src/core_plugins/console/server/wildcard_matcher.js @@ -1,4 +1,4 @@ -import { Minimatch } from 'minimatch' +import { Minimatch } from 'minimatch'; export class WildcardMatcher { constructor(wildcardPattern, emptyVal) { @@ -10,7 +10,7 @@ export class WildcardMatcher { nocase: true, matchBase: true, nocomment: true - }) + }); } match(candidate) { @@ -19,6 +19,6 @@ export class WildcardMatcher { return true; } - return this.matcher.match(candidate || '') + return this.matcher.match(candidate || ''); } }