Bump eslint rules, update code to match rules (elastic/kibana-plugin-helpers#43)
* bump @elastic/eslint-config-kibana and deps * eslint --fix * fix unused vars some exceptions for tests * move eslint-config-kibana to dev * rename create_package function * make .node-version looser, match internal checks Original commit: elastic/kibana-plugin-helpers@6fac14bd51
This commit is contained in:
parent
eb1e80f272
commit
9f37553324
|
@ -1 +1 @@
|
|||
6.10.2
|
||||
^6.0.0
|
|
@ -1,12 +1,9 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var nodeMajorVersion = parseFloat(process.version.replace(/^v(\d+)\..+/, '$1'));
|
||||
const nodeMajorVersion = parseFloat(process.version.replace(/^v(\d+)\..+/, '$1'));
|
||||
if (nodeMajorVersion < 6) {
|
||||
console.error('FATAL: kibana-plugin-helpers requires node 6+');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
require('../cli');
|
||||
require('../cli');
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var resolve = require('path').resolve;
|
||||
var readFileSync = require('fs').readFileSync;
|
||||
const resolve = require('path').resolve;
|
||||
const readFileSync = require('fs').readFileSync;
|
||||
|
||||
var configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
|
||||
var configCache = {};
|
||||
var KIBANA_ROOT_OVERRIDE = process.env.KIBANA_ROOT ? resolve(process.env.KIBANA_ROOT) : null;
|
||||
const configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
|
||||
const configCache = {};
|
||||
const KIBANA_ROOT_OVERRIDE = process.env.KIBANA_ROOT ? resolve(process.env.KIBANA_ROOT) : null;
|
||||
|
||||
module.exports = function (root) {
|
||||
if (!root) root = process.cwd();
|
||||
|
@ -13,11 +13,11 @@ module.exports = function (root) {
|
|||
}
|
||||
|
||||
// config files to read from, in the order they are merged together
|
||||
var config = configCache[root] = {};
|
||||
let config = configCache[root] = {};
|
||||
|
||||
configFiles.forEach(function (configFile) {
|
||||
try {
|
||||
var content = JSON.parse(readFileSync(resolve(root, configFile)));
|
||||
const content = JSON.parse(readFileSync(resolve(root, configFile)));
|
||||
config = Object.assign(config, content);
|
||||
} catch (e) {
|
||||
// noop
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
var resolve = require('path').resolve;
|
||||
var readFileSync = require('fs').readFileSync;
|
||||
const resolve = require('path').resolve;
|
||||
const readFileSync = require('fs').readFileSync;
|
||||
|
||||
function indent(txt, n) {
|
||||
var space = (new Array(n + 1)).join(' ');
|
||||
const space = (new Array(n + 1)).join(' ');
|
||||
return space + txt.split('\n').join('\n' + space);
|
||||
}
|
||||
|
||||
module.exports = function docs(name) {
|
||||
var md = readFileSync(resolve(__dirname, '../tasks', name, 'README.md'), 'utf8');
|
||||
const md = readFileSync(resolve(__dirname, '../tasks', name, 'README.md'), 'utf8');
|
||||
|
||||
return function () {
|
||||
console.log('\n Docs:');
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
module.exports = function enableCollectingUnknownOptions(command) {
|
||||
var origParse = command.parseOptions;
|
||||
const origParse = command.parseOptions;
|
||||
command.allowUnknownOption();
|
||||
command.parseOptions = function (argv) {
|
||||
var opts = origParse.call(this, argv);
|
||||
const opts = origParse.call(this, argv);
|
||||
this.unknownOptions = opts.unknown;
|
||||
return opts;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var run = require('./run');
|
||||
var utils = require('./utils');
|
||||
const run = require('./run');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = function () {
|
||||
console.error(
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
var resolve = require('path').resolve;
|
||||
var statSync = require('fs').statSync;
|
||||
var configFile = require('./config_file');
|
||||
const resolve = require('path').resolve;
|
||||
const statSync = require('fs').statSync;
|
||||
const configFile = require('./config_file');
|
||||
|
||||
module.exports = function (root) {
|
||||
if (!root) root = process.cwd();
|
||||
|
||||
var pkg = require(resolve(root, 'package.json'));
|
||||
var config = configFile(root);
|
||||
const pkg = require(resolve(root, 'package.json'));
|
||||
const config = configFile(root);
|
||||
|
||||
var buildSourcePatterns = [
|
||||
const buildSourcePatterns = [
|
||||
'package.json',
|
||||
'index.js',
|
||||
'{lib,public,server,webpackShims}/**/*',
|
||||
|
@ -35,7 +35,7 @@ module.exports = function (root) {
|
|||
|
||||
function fileExists(path) {
|
||||
try {
|
||||
var stat = statSync(path);
|
||||
const stat = statSync(path);
|
||||
return stat.isFile();
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var pluginConfig = require('./plugin_config');
|
||||
var tasks = require('./tasks');
|
||||
const pluginConfig = require('./plugin_config');
|
||||
const tasks = require('./tasks');
|
||||
|
||||
module.exports = function run(name, options) {
|
||||
var action = tasks[name];
|
||||
const action = tasks[name];
|
||||
if (!action) throw new Error('Invalid task: "' + name + '"');
|
||||
|
||||
var plugin = pluginConfig();
|
||||
const plugin = pluginConfig();
|
||||
return action(plugin, run, options);
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var buildTask = require('../tasks/build');
|
||||
var startTask = require('../tasks/start');
|
||||
var testAllTask = require('../tasks/test/all');
|
||||
var testBrowserTask = require('../tasks/test/browser');
|
||||
var testServerTask = require('../tasks/test/server');
|
||||
const buildTask = require('../tasks/build');
|
||||
const startTask = require('../tasks/start');
|
||||
const testAllTask = require('../tasks/test/all');
|
||||
const testBrowserTask = require('../tasks/test/browser');
|
||||
const testServerTask = require('../tasks/test/server');
|
||||
|
||||
module.exports = {
|
||||
build: buildTask,
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
var resolve = require('path').resolve;
|
||||
const resolve = require('path').resolve;
|
||||
|
||||
var pluginConfig = require('./plugin_config');
|
||||
const pluginConfig = require('./plugin_config');
|
||||
|
||||
function babelRegister() {
|
||||
var plugin = pluginConfig();
|
||||
const plugin = pluginConfig();
|
||||
require(resolve(plugin.kibanaRoot, 'src/optimize/babel/register'));
|
||||
}
|
||||
|
||||
function resolveKibanaPath(path) {
|
||||
var plugin = pluginConfig();
|
||||
const plugin = pluginConfig();
|
||||
return resolve(plugin.kibanaRoot, path);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var platform = require('os').platform();
|
||||
const platform = require('os').platform();
|
||||
|
||||
module.exports = function winCmd(cmd) {
|
||||
return /^win/.test(platform) ? cmd + '.cmd' : cmd;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
"lint": "eslint bin/ help/ tasks/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/eslint-config-kibana": "0.0.2",
|
||||
"commander": "^2.9.0",
|
||||
"del": "^2.2.2",
|
||||
"gulp-rename": "1.2.2",
|
||||
|
@ -31,9 +30,12 @@
|
|||
"doc": "docs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "4.1.8",
|
||||
"eslint": "1.10.3",
|
||||
"eslint-plugin-mocha": "1.1.0",
|
||||
"@elastic/eslint-config-kibana": "0.5.0",
|
||||
"babel-eslint": "6.1.2",
|
||||
"eslint": "3.11.1",
|
||||
"eslint-plugin-mocha": "4.7.0",
|
||||
"eslint-plugin-babel": "4.0.0",
|
||||
"eslint-plugin-react": "6.10.3",
|
||||
"jest": "^17.0.3"
|
||||
},
|
||||
"repository": {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var join = require('path').join;
|
||||
var resolve = require('path').resolve;
|
||||
var inquirer = require('inquirer');
|
||||
const join = require('path').join;
|
||||
const resolve = require('path').resolve;
|
||||
const inquirer = require('inquirer');
|
||||
|
||||
var createBuild = require('./create_build');
|
||||
var createPackage = require('./create_package');
|
||||
const createBuild = require('./create_build');
|
||||
const createPackage = require('./create_package');
|
||||
|
||||
module.exports = function (plugin, run, options) {
|
||||
options = options || {};
|
||||
var buildVersion = plugin.version;
|
||||
var kibanaVersion = (plugin.pkg.kibana && plugin.pkg.kibana.version) || plugin.pkg.version;
|
||||
var buildFiles = plugin.buildSourcePatterns;
|
||||
var buildTarget = join(plugin.root, 'build');
|
||||
let buildVersion = plugin.version;
|
||||
let kibanaVersion = (plugin.pkg.kibana && plugin.pkg.kibana.version) || plugin.pkg.version;
|
||||
let buildFiles = plugin.buildSourcePatterns;
|
||||
let buildTarget = join(plugin.root, 'build');
|
||||
|
||||
// allow source files to be overridden
|
||||
if (options.files && options.files.length) {
|
||||
|
@ -22,7 +22,7 @@ module.exports = function (plugin, run, options) {
|
|||
if (options.buildVersion) buildVersion = options.buildVersion;
|
||||
if (options.kibanaVersion) kibanaVersion = options.kibanaVersion;
|
||||
|
||||
var buildStep;
|
||||
let buildStep;
|
||||
if (kibanaVersion === 'kibana') {
|
||||
buildStep = askForKibanaVersion().then(function (customKibanaVersion) {
|
||||
return createBuild(plugin, buildTarget, buildVersion, customKibanaVersion, buildFiles);
|
||||
|
@ -41,7 +41,7 @@ module.exports = function (plugin, run, options) {
|
|||
});
|
||||
};
|
||||
|
||||
function askForKibanaVersion(cb) {
|
||||
function askForKibanaVersion() {
|
||||
return inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
|
|
|
@ -17,7 +17,7 @@ describe('build_action', () => {
|
|||
|
||||
it('creates a zip in the build directory', () => {
|
||||
return buildAction(PLUGIN).then(() => {
|
||||
var buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (!fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ describe('build_action', () => {
|
|||
|
||||
it('skips zip creation based on flag', function () {
|
||||
return buildAction(PLUGIN, noop, { skipArchive: true }).then(() => {
|
||||
var buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
const buildFile = resolve(PLUGIN_BUILD_DIR, PLUGIN.id + '-' + PLUGIN.version + '.zip');
|
||||
if (fs.existsSync(buildFile)) {
|
||||
throw new Error('Build file not found: ' + buildFile);
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ describe('build_action', () => {
|
|||
|
||||
return buildAction(PLUGIN, noop, options).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
expect(buildVersion).toBe('1.2.3');
|
||||
expect(kibanaVersion).toBe('4.5.6');
|
||||
|
@ -62,6 +63,7 @@ describe('build_action', () => {
|
|||
it('uses default file list without files option', function () {
|
||||
return buildAction(PLUGIN).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
PLUGIN.buildSourcePatterns.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
|
@ -79,6 +81,7 @@ describe('build_action', () => {
|
|||
|
||||
return buildAction(PLUGIN, noop, options).then(() => {
|
||||
expect(mockBuild.mock.calls).toHaveLength(1);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
|
||||
options.files.forEach(file => expect(files).toContain(file));
|
||||
});
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
var join = require('path').join;
|
||||
var relative = require('path').relative;
|
||||
var statSync = require('fs').statSync;
|
||||
var execFileSync = require('child_process').execFileSync;
|
||||
var del = require('del');
|
||||
var vfs = require('vinyl-fs');
|
||||
var rename = require('gulp-rename');
|
||||
const join = require('path').join;
|
||||
const relative = require('path').relative;
|
||||
const statSync = require('fs').statSync;
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
const del = require('del');
|
||||
const vfs = require('vinyl-fs');
|
||||
const rename = require('gulp-rename');
|
||||
|
||||
var rewritePackageJson = require('./rewrite_package_json');
|
||||
var gitInfo = require('./git_info');
|
||||
var winCmd = require('../../lib/win_cmd');
|
||||
const rewritePackageJson = require('./rewrite_package_json');
|
||||
const winCmd = require('../../lib/win_cmd');
|
||||
|
||||
module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaVersion, files) {
|
||||
var buildSource = plugin.root;
|
||||
var buildRoot = join(buildTarget, 'kibana', plugin.id);
|
||||
const buildSource = plugin.root;
|
||||
const buildRoot = join(buildTarget, 'kibana', plugin.id);
|
||||
|
||||
return del(buildTarget)
|
||||
.then(function () {
|
||||
|
@ -24,7 +23,7 @@ module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaV
|
|||
|
||||
// put all files inside the correct directories
|
||||
.pipe(rename(function nestFileInDir(path) {
|
||||
var nonRelativeDirname = path.dirname.replace(/^(\.\.\/?)+/g, '');
|
||||
const nonRelativeDirname = path.dirname.replace(/^(\.\.\/?)+/g, '');
|
||||
path.dirname = join(relative(buildTarget, buildRoot), nonRelativeDirname);
|
||||
}))
|
||||
|
||||
|
@ -35,7 +34,7 @@ module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaV
|
|||
})
|
||||
.then(function () {
|
||||
// install packages in build
|
||||
var options = {
|
||||
const options = {
|
||||
cwd: buildRoot,
|
||||
stdio: ['ignore', 'ignore', 'pipe'],
|
||||
};
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
var join = require('path').join;
|
||||
var relative = require('path').relative;
|
||||
var del = require('del');
|
||||
var vfs = require('vinyl-fs');
|
||||
var zip = require('gulp-zip');
|
||||
const join = require('path').join;
|
||||
const relative = require('path').relative;
|
||||
const del = require('del');
|
||||
const vfs = require('vinyl-fs');
|
||||
const zip = require('gulp-zip');
|
||||
|
||||
module.exports = function createBuild(plugin, buildVersion) {
|
||||
var buildId = `${plugin.id}-${buildVersion}`;
|
||||
var buildSource = plugin.root;
|
||||
var buildTarget = join(plugin.root, 'build');
|
||||
var buildRoot = join(buildTarget, 'kibana', plugin.id);
|
||||
module.exports = function createPackage(plugin, buildVersion) {
|
||||
const buildId = `${plugin.id}-${buildVersion}`;
|
||||
const buildTarget = join(plugin.root, 'build');
|
||||
const buildRoot = join(buildTarget, 'kibana', plugin.id);
|
||||
|
||||
// zip up the package
|
||||
return new Promise(function (resolve, reject) {
|
||||
var buildFiles = [relative(buildTarget, buildRoot) + '/**/*'];
|
||||
const buildFiles = [relative(buildTarget, buildRoot) + '/**/*'];
|
||||
|
||||
vfs.src(buildFiles, { cwd: buildTarget, base: buildTarget })
|
||||
.pipe(zip(`${buildId}.zip`))
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
var execFileSync = require('child_process').execFileSync;
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
|
||||
module.exports = function gitInfo(rootPath) {
|
||||
try {
|
||||
var LOG_SEPARATOR = '||';
|
||||
var commitCount = execFileSync('git', ['rev-list', '--count', 'HEAD'], {
|
||||
const LOG_SEPARATOR = '||';
|
||||
const commitCount = execFileSync('git', ['rev-list', '--count', 'HEAD'], {
|
||||
cwd: rootPath,
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
encoding: 'utf8',
|
||||
});
|
||||
var logLine = execFileSync('git', ['log', '--pretty=%h' + LOG_SEPARATOR + '%cD', '-n', '1'], {
|
||||
const logLine = execFileSync('git', ['log', '--pretty=%h' + LOG_SEPARATOR + '%cD', '-n', '1'], {
|
||||
cwd: rootPath,
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
encoding: 'utf8',
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var map = require('through2-map').obj;
|
||||
var gitInfo = require('./git_info');
|
||||
const map = require('through2-map').obj;
|
||||
const gitInfo = require('./git_info');
|
||||
|
||||
module.exports = function rewritePackage(buildSource, buildVersion, kibanaVersion) {
|
||||
return map(function (file) {
|
||||
if (file.basename === 'package.json' && file.dirname === buildSource) {
|
||||
var pkg = JSON.parse(file.contents.toString('utf8'));
|
||||
const pkg = JSON.parse(file.contents.toString('utf8'));
|
||||
|
||||
// rewrite the target kibana version while the
|
||||
// file is on it's way to the archive
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var execFileSync = require('child_process').execFileSync;
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
|
||||
module.exports = function (plugin, run, options) {
|
||||
options = options || {};
|
||||
|
||||
var cmd = (process.platform === 'win32') ? 'bin\\kibana.bat' : 'bin/kibana';
|
||||
var args = ['--dev', '--plugin-path', plugin.root];
|
||||
const cmd = (process.platform === 'win32') ? 'bin\\kibana.bat' : 'bin/kibana';
|
||||
let args = ['--dev', '--plugin-path', plugin.root];
|
||||
|
||||
if (options.flags) {
|
||||
args = args.concat(options.flags);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var execFileSync = require('child_process').execFileSync;
|
||||
var winCmd = require('../../../lib/win_cmd');
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
const winCmd = require('../../../lib/win_cmd');
|
||||
|
||||
module.exports = function testBrowserAction(plugin, run, options) {
|
||||
options = options || {};
|
||||
|
||||
var kbnServerArgs = [
|
||||
const kbnServerArgs = [
|
||||
'--kbnServer.plugin-path=' + plugin.root
|
||||
];
|
||||
|
||||
|
@ -14,8 +14,8 @@ module.exports = function testBrowserAction(plugin, run, options) {
|
|||
kbnServerArgs.push('--kbnServer.tests_bundle.pluginId=' + plugin.id);
|
||||
}
|
||||
|
||||
var task = (options.dev) ? 'test:dev' : 'test:browser';
|
||||
var args = ['run', task, '--'].concat(kbnServerArgs);
|
||||
const task = (options.dev) ? 'test:dev' : 'test:browser';
|
||||
const args = ['run', task, '--'].concat(kbnServerArgs);
|
||||
execFileSync(winCmd('npm'), args, {
|
||||
cwd: plugin.kibanaRoot,
|
||||
stdio: ['ignore', 1, 2]
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
var resolve = require('path').resolve;
|
||||
var delimiter = require('path').delimiter;
|
||||
var execFileSync = require('child_process').execFileSync;
|
||||
var winCmd = require('../../../lib/win_cmd');
|
||||
const resolve = require('path').resolve;
|
||||
const delimiter = require('path').delimiter;
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
const winCmd = require('../../../lib/win_cmd');
|
||||
|
||||
module.exports = function (plugin, run, options) {
|
||||
options = options || {};
|
||||
var kibanaBins = resolve(plugin.kibanaRoot, 'node_modules/.bin');
|
||||
var mochaSetupJs = resolve(plugin.kibanaRoot, 'test/mocha_setup.js');
|
||||
var testPaths = plugin.serverTestPatterns;
|
||||
const kibanaBins = resolve(plugin.kibanaRoot, 'node_modules/.bin');
|
||||
const mochaSetupJs = resolve(plugin.kibanaRoot, 'test/mocha_setup.js');
|
||||
let testPaths = plugin.serverTestPatterns;
|
||||
|
||||
// allow server test files to be overridden
|
||||
if (options.files && options.files.length) {
|
||||
testPaths = options.files;
|
||||
}
|
||||
|
||||
var fullCmd = resolve(plugin.kibanaRoot, 'node_modules', '.bin', 'mocha');
|
||||
var cmd = winCmd(fullCmd);
|
||||
var args = ['--require', mochaSetupJs].concat(testPaths);
|
||||
var path = `${kibanaBins}${delimiter}${process.env.PATH}`;
|
||||
const fullCmd = resolve(plugin.kibanaRoot, 'node_modules', '.bin', 'mocha');
|
||||
const cmd = winCmd(fullCmd);
|
||||
const args = ['--require', mochaSetupJs].concat(testPaths);
|
||||
const path = `${kibanaBins}${delimiter}${process.env.PATH}`;
|
||||
|
||||
execFileSync(cmd, args, {
|
||||
cwd: plugin.root,
|
||||
|
|
Loading…
Reference in a new issue