Skip to content

Commit

Permalink
Upgrade to eslint 4 (#14862)
Browse files Browse the repository at this point in the history
* [eslint] upgrade to 4.10.0

* [eslint-config-kibana] limit jest config to jest test files

* [ui_framework] remove trailing comma from rest-spreads

* [dashboard/tests] tag jest helpers with .test.js suffix

* explicitly import expect.js where used

* [eslint] apply auto-fixes

* [eslint] manually add/wrap some parens for compliance

* [npm] point to local packages for testing/review

* [jest] remove .test extension from jest helpers

* [ui_framework] fix trailing comma removal from 3bc661a

* [packages] upgrade eslint packages
  • Loading branch information
spalger authored Nov 15, 2017
1 parent 94b2b32 commit 5cddc10
Show file tree
Hide file tree
Showing 380 changed files with 8,797 additions and 8,772 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@
"yauzl": "2.7.0"
},
"devDependencies": {
"@elastic/eslint-config-kibana": "0.13.0",
"@elastic/eslint-config-kibana": "0.14.0",
"@elastic/eslint-import-resolver-kibana": "0.9.0",
"@elastic/eslint-plugin-kibana-custom": "1.0.3",
"@elastic/eslint-plugin-kibana-custom": "1.1.0",
"angular-mocks": "1.4.7",
"babel-eslint": "7.2.3",
"babel-eslint": "8.0.2",
"backport": "1.1.1",
"chai": "3.5.0",
"chalk": "2.0.1",
Expand All @@ -229,13 +229,13 @@
"classnames": "2.2.5",
"enzyme": "2.9.1",
"enzyme-to-json": "1.4.5",
"eslint": "3.19.0",
"eslint-plugin-babel": "4.1.1",
"eslint-plugin-import": "2.3.0",
"eslint-plugin-jest": "21.0.0",
"eslint-plugin-mocha": "4.9.0",
"eslint": "4.10.0",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jest": "21.2.0",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-prefer-object-spread": "1.2.1",
"eslint-plugin-react": "7.1.0",
"eslint-plugin-react": "7.4.0",
"event-stream": "3.3.2",
"expect.js": "0.3.1",
"faker": "1.1.0",
Expand Down
27 changes: 16 additions & 11 deletions packages/eslint-config-kibana/jest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module.exports = {
plugins: [
'jest',
],
overrides: [
{
files: ['**/*.test.js'],
plugins: [
'jest',
],

env: {
'jest/globals': true,
},
env: {
'jest/globals': true,
},

rules: {
'jest/no-disabled-tests': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
},
rules: {
'jest/no-disabled-tests': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
},
}
]
};
4 changes: 2 additions & 2 deletions packages/eslint-config-kibana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elastic/eslint-config-kibana",
"version": "0.13.0",
"version": "0.14.0",
"description": "The eslint config used by the kibana team",
"main": ".eslintrc.js",
"scripts": {
Expand All @@ -18,7 +18,7 @@
},
"homepage": "https://github.com/elastic/eslint-config-kibana#readme",
"peerDependencies": {
"babel-eslint": "^7.2.3",
"babel-eslint": "^8.0.0",
"eslint": "^4.1.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.6.0",
Expand Down
17 changes: 12 additions & 5 deletions packages/eslint-plugin-kibana-custom/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports.rules = {
'no-default-export': context => ({
ExportDefaultDeclaration: (node) => {
context.report(node, 'Default exports not allowed.');
module.exports = {
rules: {
'no-default-export': {
meta: {
schema: []
},
create: context => ({
ExportDefaultDeclaration: (node) => {
context.report(node, 'Default exports not allowed.');
}
})
}
})
}
};
2 changes: 1 addition & 1 deletion packages/eslint-plugin-kibana-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elastic/eslint-plugin-kibana-custom",
"version": "1.0.3",
"version": "1.1.0",
"description": "Custom ESLint rules for Kibana",
"repository": {
"type": "git",
Expand Down
30 changes: 15 additions & 15 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) :
const program = new Command('bin/kibana');

program
.version(pkg.version)
.description(
'Kibana is an open source (Apache Licensed), browser ' +
.version(pkg.version)
.description(
'Kibana is an open source (Apache Licensed), browser ' +
'based analytics and search dashboard for Elasticsearch.'
);
);

// attach commands
serveCommand(program);

program
.command('help <command>')
.description('Get the help for a specific command')
.action(function (cmdName) {
const cmd = _.find(program.commands, { _name: cmdName });
if (!cmd) return program.error(`unknown command ${cmdName}`);
cmd.help();
});
.command('help <command>')
.description('Get the help for a specific command')
.action(function (cmdName) {
const cmd = _.find(program.commands, { _name: cmdName });
if (!cmd) return program.error(`unknown command ${cmdName}`);
cmd.help();
});

program
.command('*', null, { noHelp: true })
.action(function (cmd) {
program.error(`unknown command ${cmd}`);
});
.command('*', null, { noHelp: true })
.action(function (cmd) {
program.error(`unknown command ${cmd}`);
});

// check for no command name
const subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cluster/base_path_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export default class BasePathProxy {
});
}
})
.return(undefined)
.nodeify(reply);
.return(undefined)
.nodeify(reply);
}
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/cli/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Command.prototype.error = function (err) {
if (err && err.message) err = err.message;

console.log(
`
`
${red(' ERROR ')} ${err}
${help(this, ' ')}
Expand All @@ -20,7 +20,7 @@ ${help(this, ' ')}

Command.prototype.defaultHelp = function () {
console.log(
`
`
${help(this, ' ')}
`
Expand Down
4 changes: 2 additions & 2 deletions src/cli/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function help(command, spaces) {
const cmdDef = !defCmd ? '' : `=${defCmd._name}`;

return (
`
`
Usage: ${command._name} [command${cmdDef}] [options]
${desc}
Expand Down Expand Up @@ -58,7 +58,7 @@ function cmdHelp(cmd) {
if (!cmd) return '';
return (

`
`
"${cmd._name}" Options:
${indent(cmd.optionHelp(), 2)}
Expand Down
168 changes: 84 additions & 84 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,109 +79,109 @@ export default function (program) {
const command = program.command('serve');

command
.description('Run the kibana server')
.collectUnknownOptions()
.option('-e, --elasticsearch <uri>', 'Elasticsearch instance')
.option(
'-c, --config <path>',
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well. ' +
.description('Run the kibana server')
.collectUnknownOptions()
.option('-e, --elasticsearch <uri>', 'Elasticsearch instance')
.option(
'-c, --config <path>',
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well. ' +
'Use multiple --config args to include multiple config files.',
configPathCollector,
[ getConfig() ]
)
.option('-p, --port <port>', 'The port to bind to', parseInt)
.option('-q, --quiet', 'Prevent all logging except errors')
.option('-Q, --silent', 'Prevent all logging')
.option('--verbose', 'Turns on verbose logging')
.option('-H, --host <host>', 'The host to bind to')
.option('-l, --log-file <path>', 'The file to log to')
.option(
'--plugin-dir <path>',
'A path to scan for plugins, this can be specified multiple ' +
configPathCollector,
[ getConfig() ]
)
.option('-p, --port <port>', 'The port to bind to', parseInt)
.option('-q, --quiet', 'Prevent all logging except errors')
.option('-Q, --silent', 'Prevent all logging')
.option('--verbose', 'Turns on verbose logging')
.option('-H, --host <host>', 'The host to bind to')
.option('-l, --log-file <path>', 'The file to log to')
.option(
'--plugin-dir <path>',
'A path to scan for plugins, this can be specified multiple ' +
'times to specify multiple directories',
pluginDirCollector,
[
fromRoot('plugins'),
fromRoot('src/core_plugins')
]
)
.option(
'--plugin-path <path>',
'A path to a plugin which should be included by the server, ' +
pluginDirCollector,
[
fromRoot('plugins'),
fromRoot('src/core_plugins')
]
)
.option(
'--plugin-path <path>',
'A path to a plugin which should be included by the server, ' +
'this can be specified multiple times to specify multiple paths',
pluginPathCollector,
[]
)
.option('--plugins <path>', 'an alias for --plugin-dir', pluginDirCollector);
pluginPathCollector,
[]
)
.option('--plugins <path>', 'an alias for --plugin-dir', pluginDirCollector);

if (canCluster) {
command
.option('--dev', 'Run the server with development mode defaults')
.option('--ssl', 'Run the dev server using HTTPS')
.option('--no-base-path', 'Don\'t put a proxy in front of the dev server, which adds a random basePath')
.option('--no-watch', 'Prevents automatic restarts of the server in --dev mode');
.option('--dev', 'Run the server with development mode defaults')
.option('--ssl', 'Run the dev server using HTTPS')
.option('--no-base-path', 'Don\'t put a proxy in front of the dev server, which adds a random basePath')
.option('--no-watch', 'Prevents automatic restarts of the server in --dev mode');
}

command
.action(async function (opts) {
if (opts.dev) {
try {
const kbnDevConfig = fromRoot('config/kibana.dev.yml');
if (statSync(kbnDevConfig).isFile()) {
opts.config.push(kbnDevConfig);
}
} catch (err) {
.action(async function (opts) {
if (opts.dev) {
try {
const kbnDevConfig = fromRoot('config/kibana.dev.yml');
if (statSync(kbnDevConfig).isFile()) {
opts.config.push(kbnDevConfig);
}
} catch (err) {
// ignore, kibana.dev.yml does not exist
}
}
}

const getCurrentSettings = () => readServerSettings(opts, this.getUnknownOptions());
const settings = getCurrentSettings();
const getCurrentSettings = () => readServerSettings(opts, this.getUnknownOptions());
const settings = getCurrentSettings();

if (canCluster && opts.dev && !isWorker) {
if (canCluster && opts.dev && !isWorker) {
// stop processing the action and handoff to cluster manager
const ClusterManager = require('../cluster/cluster_manager');
new ClusterManager(opts, settings);
return;
}
const ClusterManager = require('../cluster/cluster_manager');
new ClusterManager(opts, settings);
return;
}

let kbnServer = {};
const KbnServer = require('../../server/kbn_server');
try {
kbnServer = new KbnServer(settings);
await kbnServer.ready();
} catch (error) {
const { server } = kbnServer;

switch (error.code) {
case 'EADDRINUSE':
logFatal(`Port ${error.port} is already in use. Another instance of Kibana may be running!`, server);
break;

case 'InvalidConfig':
logFatal(error.message, server);
break;

default:
logFatal(error, server);
break;
let kbnServer = {};
const KbnServer = require('../../server/kbn_server');
try {
kbnServer = new KbnServer(settings);
await kbnServer.ready();
} catch (error) {
const { server } = kbnServer;

switch (error.code) {
case 'EADDRINUSE':
logFatal(`Port ${error.port} is already in use. Another instance of Kibana may be running!`, server);
break;

case 'InvalidConfig':
logFatal(error.message, server);
break;

default:
logFatal(error, server);
break;
}

kbnServer.close();
const exitCode = error.processExitCode == null ? 1 : error.processExitCode;
// eslint-disable-next-line no-process-exit
process.exit(exitCode);
}

kbnServer.close();
const exitCode = error.processExitCode == null ? 1 : error.processExitCode;
// eslint-disable-next-line no-process-exit
process.exit(exitCode);
}
process.on('SIGHUP', function reloadConfig() {
const settings = getCurrentSettings();
kbnServer.server.log(['info', 'config'], 'Reloading logging configuration due to SIGHUP.');
kbnServer.applyLoggingConfiguration(settings);
kbnServer.server.log(['info', 'config'], 'Reloaded logging configuration due to SIGHUP.');
});

process.on('SIGHUP', function reloadConfig() {
const settings = getCurrentSettings();
kbnServer.server.log(['info', 'config'], 'Reloading logging configuration due to SIGHUP.');
kbnServer.applyLoggingConfiguration(settings);
kbnServer.server.log(['info', 'config'], 'Reloaded logging configuration due to SIGHUP.');
return kbnServer;
});

return kbnServer;
});
}

function logFatal(message, server) {
Expand Down
Loading

0 comments on commit 5cddc10

Please sign in to comment.