use eslint autofix to start fixing violations

This commit is contained in:
spalger
2017-06-14 18:48:24 -07:00
parent da8e558817
commit 3d75c6ff0f
97 changed files with 1281 additions and 1280 deletions

View File

@ -9,39 +9,39 @@
*/
module.exports = YamlDoc;
var _ = require('lodash');
var expect = require('expect.js');
var clientManager = require('./client_manager');
var inspect = require('util').inspect;
const _ = require('lodash');
const expect = require('expect.js');
const clientManager = require('./client_manager');
const inspect = require('util').inspect;
var implementedFeatures = ['gtelte', 'regex', 'benchmark', 'stash_in_path', 'groovy_scripting'];
const implementedFeatures = ['gtelte', 'regex', 'benchmark', 'stash_in_path', 'groovy_scripting'];
/**
* The version that ES is running, in comparable string form XXX-XXX-XXX, fetched when needed
* @type {String}
*/
var ES_VERSION = null;
let ES_VERSION = null;
// core expression for finding a version
var versionExp = '((?:\\d+\\.){0,2}\\d+)(?:[\\.\\-]\\w+)?|';
const versionExp = '((?:\\d+\\.){0,2}\\d+)(?:[\\.\\-]\\w+)?|';
// match all whitespace within a "regexp" match arg
var reWhitespaceRE = /\s+/g;
const reWhitespaceRE = /\s+/g;
// match all comments within a "regexp" match arg
var reCommentsRE = /([\S\s]?)#[^\n]*\n/g;
const reCommentsRE = /([\S\s]?)#[^\n]*\n/g;
/**
* Regular Expression to extract a version number from a string
* @type {RegExp}
*/
var versionRE = new RegExp('^(?:' + versionExp + ')$');
const versionRE = new RegExp('^(?:' + versionExp + ')$');
/**
* Regular Expression to extract a version range from a string
* @type {RegExp}
*/
var versionRangeRE = new RegExp('^(?:' + versionExp + ')\\s*\\-\\s*(?:' + versionExp + ')$');
const versionRangeRE = new RegExp('^(?:' + versionExp + ')\\s*\\-\\s*(?:' + versionExp + ')$');
/**
* Fetches the client.info, and parses out the version number to a comparable string
@ -70,7 +70,7 @@ function versionToComparableString(version, def) {
return def;
}
var parts = _.map(version.split('.'), function (part) {
const parts = _.map(version.split('.'), function (part) {
part = '' + _.parseInt(part);
return (new Array(Math.max(4 - part.length, 0))).join('0') + part;
});
@ -106,7 +106,7 @@ function rangeMatchesCurrentVersion(rangeString, done) {
function YamlDoc(doc, file) {
var self = this;
const self = this;
self.file = file;
self.description = _.keys(doc).shift();
@ -116,7 +116,7 @@ function YamlDoc(doc, file) {
// setup the actions, creating a bound and testable method for each
self._actions = _.map(self.flattenTestActions(doc[self.description]), function (action) {
// get the method that will do the action
var method = self['do_' + action.name];
const method = self['do_' + action.name];
// check that it's a function
expect(method || 'YamlDoc#' + action.name).to.be.a('function');
@ -175,14 +175,14 @@ function YamlDoc(doc, file) {
YamlDoc.compareRangeToVersion = function (range, version) {
expect(range).to.match(versionRangeRE);
var rangeMatch = versionRangeRE.exec(range);
const rangeMatch = versionRangeRE.exec(range);
expect(version).to.match(versionRE);
var versionMatch = versionRE.exec(version);
const versionMatch = versionRE.exec(version);
var min = versionToComparableString(rangeMatch[1], -Infinity);
var max = versionToComparableString(rangeMatch[2], Infinity);
var comp = versionToComparableString(versionMatch[1], Infinity);
const min = versionToComparableString(rangeMatch[1], -Infinity);
const max = versionToComparableString(rangeMatch[2], Infinity);
const comp = versionToComparableString(versionMatch[1], Infinity);
return (min === -Infinity || min <= comp) && (max === Infinity || max >= comp);
};
@ -199,7 +199,7 @@ YamlDoc.prototype = {
flattenTestActions: function (config) {
// creates [ [ {name:"", args:"" }, ... ], ... ]
// from [ {name:args, name:args}, {name:args} ]
var actionSets = _.map(config, function (set) {
const actionSets = _.map(config, function (set) {
return _.map(_.toPairs(set), function (pair) {
return { name: pair[0], args: pair[1] };
});
@ -219,7 +219,7 @@ YamlDoc.prototype = {
* @return {undefined}
*/
each: function (ittr) {
for (var i = 0; i < this._actions.length; i++) {
for (let i = 0; i < this._actions.length; i++) {
if (ittr(this._actions[i].testable, this._actions[i].name) === false) {
break;
}
@ -249,9 +249,9 @@ YamlDoc.prototype = {
* @return {*} - The value requested, or undefined if it was not found
*/
get: function (path, from) {
var self = this;
var log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {};
var i;
const self = this;
const log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {};
let i;
if (path === '$body') {
// shortcut, the test just wants the whole body
@ -273,10 +273,10 @@ YamlDoc.prototype = {
log('getting', path, 'from', from);
var steps = _.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
const steps = _.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
return step.replace(/\uffff/g, '.');
});
var remainingSteps;
let remainingSteps;
for (i = 0; from != null && i < steps.length; i++) {
if (from[steps[i]] === void 0) {
@ -319,8 +319,8 @@ YamlDoc.prototype = {
}
if (args.features) {
var features = Array.isArray(args.features) ? args.features : [args.features];
var notImplemented = _.difference(features, implementedFeatures);
const features = Array.isArray(args.features) ? args.features : [args.features];
const notImplemented = _.difference(features, implementedFeatures);
if (notImplemented.length) {
if (this.description === 'setup') {
@ -343,10 +343,10 @@ YamlDoc.prototype = {
* @return {[type]} [description]
*/
do_do: function (args, done) {
var catcher;
let catcher;
if (process.env.LOG_DO) {
var __done = done;
const __done = done;
done = function (err, resp) {
console.log('doing', clientActionName, 'with', params);
console.log('got', resp);
@ -388,7 +388,7 @@ YamlDoc.prototype = {
delete args.catch;
var inputParams = {};
const inputParams = {};
// resolve the headers for a request
if (args.headers) {
@ -396,25 +396,25 @@ YamlDoc.prototype = {
delete args.headers;
}
var otherKeys = _.keys(args);
var action = otherKeys.shift();
const otherKeys = _.keys(args);
const action = otherKeys.shift();
if (otherKeys.length) {
return done(new TypeError('Unexpected top-level args to "do": ' + otherKeys.join(', ')));
}
var client = clientManager.get();
const client = clientManager.get();
var clientActionName = _.map(action.split('.'), _.camelCase).join('.');
var clientAction = this.get(clientActionName, client);
const clientAction = this.get(clientActionName, client);
_.assign(inputParams, args[action]);
var params = _.transform(inputParams, _.bind(function (params, val, name) {
var camelName = _.camelCase(name);
const camelName = _.camelCase(name);
// search through the params and url peices to find this param name
var paramName = name;
var spec = clientAction && clientAction.spec;
var knownParam = spec && spec.params && spec.params[camelName];
var knownUrlParam = spec && !knownParam && !!_.find(spec.url ? [spec.url] : spec.urls, function (url) {
let paramName = name;
const spec = clientAction && clientAction.spec;
const knownParam = spec && spec.params && spec.params[camelName];
const knownUrlParam = spec && !knownParam && !!_.find(spec.url ? [spec.url] : spec.urls, function (url) {
if ((url.opt && url.opt[camelName]) || (url.req && url.req[camelName])) {
return true;
}
@ -447,8 +447,8 @@ YamlDoc.prototype = {
catcher = null;
}
var timeoutId;
var cb = _.bind(function (error, body) {
let timeoutId;
const cb = _.bind(function (error, body) {
this._last_requests_response = body;
clearTimeout(timeoutId);
@ -473,7 +473,7 @@ YamlDoc.prototype = {
done(error);
}, this);
var req = clientAction.call(client, params, cb);
const req = clientAction.call(client, params, cb);
timeoutId = setTimeout(function () {
// request timed out, so we will skip the rest of the tests and continue
req.abort();
@ -507,7 +507,7 @@ YamlDoc.prototype = {
* @return {undefined}
*/
do_is_true: function (path) {
var val = this.get(path);
const val = this.get(path);
try {
expect(Boolean(val)).to.be(true, 'path: ' + path);
} catch (e) {
@ -523,7 +523,7 @@ YamlDoc.prototype = {
* @return {undefined}
*/
do_is_false: function (path) {
var val = this.get(path);
const val = this.get(path);
try {
expect(Boolean(val)).to.be(false, 'path: ' + path);
} catch (e) {
@ -563,7 +563,7 @@ YamlDoc.prototype = {
* @return {undefined}
*/
do_match: function (args) {
var self = this;
const self = this;
// recursively replace all $var within args
_.forOwn(args, function recurse(val, key, lvl) {
@ -579,10 +579,10 @@ YamlDoc.prototype = {
});
_.forOwn(args, _.bind(function (match, path) {
var origMatch = match;
const origMatch = match;
var maybeRE = false;
var usedRE = false;
let maybeRE = false;
let usedRE = false;
if (_.isString(match)) {
// convert the matcher into a compatible string for building a regexp
@ -599,8 +599,8 @@ YamlDoc.prototype = {
// whitespace is represented with \s
.replace(reWhitespaceRE, '');
var startsWithSlash = maybeRE[0] === '/';
var endsWithSlash = maybeRE[maybeRE.length - 1] === '/';
const startsWithSlash = maybeRE[0] === '/';
const endsWithSlash = maybeRE[maybeRE.length - 1] === '/';
if (startsWithSlash && endsWithSlash) {
usedRE = true;
@ -608,8 +608,8 @@ YamlDoc.prototype = {
}
}
var val = this.get(path);
var test = 'eql';
let val = this.get(path);
let test = 'eql';
if (match instanceof RegExp) {
test = 'match';
@ -622,7 +622,7 @@ YamlDoc.prototype = {
try {
expect(val).to[test](match);
} catch (e) {
var msg = [
const msg = [
'\nUnable to match',
inspect(match),
'with the path',