diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..1fa83a552 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +src/_* +src/bower_es_js +src/lib/apis diff --git a/Gruntfile.js b/Gruntfile.js index 96ad6350d..ef986ba9f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,3 @@ -'use strict'; - module.exports = function (grunt) { // load plugins require('load-grunt-config')(grunt, { diff --git a/grunt/config/clean.js b/grunt/config/clean.js index 4998e758b..5eee123b8 100644 --- a/grunt/config/clean.js +++ b/grunt/config/clean.js @@ -2,4 +2,4 @@ module.exports = { dist: { src: ['<%= distDir %>'] } -}; \ No newline at end of file +}; diff --git a/grunt/config/compress.js b/grunt/config/compress.js index 5c3d1db53..4298f1070 100644 --- a/grunt/config/compress.js +++ b/grunt/config/compress.js @@ -11,8 +11,8 @@ function archive(out) { } module.exports = { - master_zip: archive('elasticsearch-js-master.zip'), - master_tarball: archive('elasticsearch-js-master.tar.gz'), - release_zip: archive('elasticsearch-js-<%= package.version %>.zip'), - release_tarball: archive('elasticsearch-js-<%= package.version %>.tar.gz') -}; \ No newline at end of file + master_zip: archive('elasticsearch-js-master.zip'), + master_tarball: archive('elasticsearch-js-master.tar.gz'), + release_zip: archive('elasticsearch-js-<%= package.version %>.zip'), + release_tarball: archive('elasticsearch-js-<%= package.version %>.tar.gz') +}; diff --git a/grunt/config/concat.js b/grunt/config/concat.js index 7bfabc9fd..b9434bd38 100644 --- a/grunt/config/concat.js +++ b/grunt/config/concat.js @@ -15,4 +15,4 @@ module.exports = { footer: '\n}());' } } -}; \ No newline at end of file +}; diff --git a/grunt/config/copy.js b/grunt/config/copy.js index 1f6d57aba..8ae070ea7 100644 --- a/grunt/config/copy.js +++ b/grunt/config/copy.js @@ -11,4 +11,4 @@ module.exports = { dest: '<%= bowerSubmodule %>', expand: true } -}; \ No newline at end of file +}; diff --git a/grunt/config/mochacov.js b/grunt/config/mochacov.js index eec8f7d6e..dd896a0a7 100644 --- a/grunt/config/mochacov.js +++ b/grunt/config/mochacov.js @@ -78,4 +78,4 @@ grunt.registerTask('mocha_jenkins_integration', function (branch) { grunt.task.run('mochacov:jenkins_integration'); }); -module.exports = config; \ No newline at end of file +module.exports = config; diff --git a/grunt/config/open.js b/grunt/config/open.js index f67d0ab53..2043afa59 100644 --- a/grunt/config/open.js +++ b/grunt/config/open.js @@ -3,4 +3,4 @@ module.exports = { path: 'coverage.html', app: 'Google Chrome' } -}; \ No newline at end of file +}; diff --git a/grunt/config/prompt.js b/grunt/config/prompt.js index 772af5e18..ba7823c6b 100644 --- a/grunt/config/prompt.js +++ b/grunt/config/prompt.js @@ -9,4 +9,4 @@ module.exports = { }] } } -}; \ No newline at end of file +}; diff --git a/grunt/config/s3.js b/grunt/config/s3.js index 73cd1ac47..0bca06e86 100644 --- a/grunt/config/s3.js +++ b/grunt/config/s3.js @@ -22,4 +22,4 @@ module.exports = { } } } -}; \ No newline at end of file +}; diff --git a/grunt/config/saucelabs-mocha.js b/grunt/config/saucelabs-mocha.js index e7bd8cabf..54b681983 100644 --- a/grunt/config/saucelabs-mocha.js +++ b/grunt/config/saucelabs-mocha.js @@ -33,4 +33,4 @@ module.exports = { ] } } -}; \ No newline at end of file +}; diff --git a/grunt/utils.js b/grunt/utils.js index 8a3405c67..a880791b6 100644 --- a/grunt/utils.js +++ b/grunt/utils.js @@ -31,19 +31,19 @@ utils.minorVersion = function (version) { utils.increaseVersion = function (version, type) { var i; switch (type) { - case 'major': - i = 0; - break; - case 'minor': - i = 1; - break; - case 'bug': - case 'patch': - case 'bugfix': - i = 2; - break; - default: - throw new TypeError('unexpected version bump type'); + case 'major': + i = 0; + break; + case 'minor': + i = 1; + break; + case 'bug': + case 'patch': + case 'bugfix': + i = 2; + break; + default: + throw new TypeError('unexpected version bump type'); } // breakout the current version diff --git a/package.json b/package.json index e9a7f2c56..3220ce49a 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "dependencies": { "chalk": "^1.0.0", "forever-agent": "^0.6.0", - "lodash": "^3.10.0", + "lodash": "^4.12.0", "lodash-compat": "^3.0.0", "promise": "^7.1.1" }, @@ -107,7 +107,8 @@ "scripts": { "test": "grunt test", "generate": "node scripts/generate", - "grunt": "grunt" + "grunt": "grunt", + "eslint": "eslint src scripts test grunt Gruntfile.js" }, "engines": { "node": ">=0.8" diff --git a/scripts/Version.js b/scripts/Version.js index 93efcd599..bfcfcebeb 100644 --- a/scripts/Version.js +++ b/scripts/Version.js @@ -1,6 +1,6 @@ var _ = require('lodash'); -var package = require('../package.json'); -var branches = package.config.supported_es_branches; +var pkg = require('../package.json'); +var branches = pkg.config.supported_es_branches; var semver = require('semver'); var maxMinorVersion = function (majorV) { @@ -48,7 +48,7 @@ Version.prototype.mergeOpts = function (opts) { return self.satisfies(rule.version); }) .map(_.ary(_.partialRight(_.omit, 'version'), 1)) - .concat(_.rest(arguments)) + .concat(_.tail(arguments)) .reverse() .reduce(_.merge, {}); }; diff --git a/scripts/_spawn.js b/scripts/_spawn.js index d5ed4e1e7..3efdd7d99 100644 --- a/scripts/_spawn.js +++ b/scripts/_spawn.js @@ -60,4 +60,4 @@ function _spawn(cmd, args, opts, cb) { _spawn.exec = function (cmd, opts, cb) { return _spawn('/bin/sh', ['-c', cmd], opts, cb); -}; \ No newline at end of file +}; diff --git a/scripts/ci.js b/scripts/ci.js index 9403784c2..bc6bda3d3 100644 --- a/scripts/ci.js +++ b/scripts/ci.js @@ -23,7 +23,7 @@ var through2 = require('through2'); var map = require('through2-map'); var split = require('split'); var join = require('path').join; -var child_process = require('child_process'); +var cp = require('child_process'); var chalk = require('chalk'); var format = require('util').format; @@ -59,10 +59,10 @@ task('SAUCE_LABS', false, function () { return new Promise(function (resolve, reject) { // build the clients and start the server, once the server is ready call trySaucelabs() var serverTasks = ['browser_clients:build', 'run:browser_test_server:keepalive']; - spawn(GRUNT, serverTasks, function (cp) { + spawn(GRUNT, serverTasks, function (proc) { var toLines = split(); - cp.stdout + proc.stdout .pipe(toLines) .pipe(through2(function (line, enc, cb) { cb(); @@ -71,11 +71,11 @@ task('SAUCE_LABS', false, function () { trySaucelabs() - .finally(function () { cp && cp.kill(); }) + .finally(function () { if (proc) proc.kill(); }) .then(resolve, reject); - cp.on('exit', function () { cp = null; }); - cp.stdout.unpipe(toLines); + proc.on('exit', function () { proc = null; }); + proc.stdout.unpipe(toLines); toLines.end(); })); }) @@ -132,25 +132,30 @@ task('CHECK_COVERAGE', false, function () { execTask('SETUP', function () { return Promise.try(function readVersion() { if (!ENV.ES_V) { - if (ENV.ES_RELEASE) + if (ENV.ES_RELEASE) { return ['v' + ENV.ES_RELEASE, ENV.ES_RELEASE]; + } - if (ENV.ES_REF) + if (ENV.ES_REF) { return [ENV.ES_REF, null]; + } } var match; - if (match = ENV.ES_V.match(/^(.*)_nightly$/)) + if (match = ENV.ES_V.match(/^(.*)_nightly$/)) { return [match[1], null]; + } - if (/^(?:1\.\d+|0\.90)\..*$/.test(ENV.ES_V)) + if (/^(?:1\.\d+|0\.90)\..*$/.test(ENV.ES_V)) { return ['v' + ENV.ES_V, ENV.ES_V]; + } throw new Error('unable to parse ES_V ' + ENV.ES_V); }) .then(function readOtherConf(ver) { - if (!ver) + if (!ver) { throw new Error('Unable to run the ci script without at least an ES_REF or ES_RELEASE environment var.'); + } log('ES_PORT:', ENV.ES_PORT = parseInt(ENV.ES_PORT || 9400, 10)); log('ES_HOST:', ENV.ES_HOST = ENV.ES_HOST || 'localhost'); @@ -162,8 +167,9 @@ execTask('SETUP', function () { else delete ENV.ES_RELEASE; }) .then(function readTasks() { - if (!ENV.RUN) - return _.where(TASKS, { default: true }); + if (!ENV.RUN) { + return _.filter(TASKS, { default: true }); + } return ENV.RUN .split(',') @@ -196,7 +202,7 @@ execTask('SETUP', function () { }); }); -/****** +/** **** * utils ******/ function log() { @@ -275,25 +281,25 @@ function execTask(name, task) { function spawn(file, args, block) { return new Promise(function (resolve, reject) { - var cp = child_process.spawn(file, args, { + var proc = cp.spawn(file, args, { cwd: ROOT, env: ENV, stdio: [0, 'pipe', 'pipe'] }); - cp.stdout.pipe(taskOut, { end: false }); - cp.stderr.pipe(taskOut, { end: false }); + proc.stdout.pipe(taskOut, { end: false }); + proc.stderr.pipe(taskOut, { end: false }); var stdout = ''; - cp.stdout + proc.stdout .pipe(through2(function (chunk, enc, cb) { stdout += chunk; cb(); })); - block && block(cp); + if (block) block(proc); - cp.on('exit', function (code) { + proc.on('exit', function (code) { if (code > 0) { reject(new Error('non-zero exit code: ' + code)); } else { @@ -301,13 +307,13 @@ function spawn(file, args, block) { } }); - cp.on('error', function (origErr) { + proc.on('error', function (origErr) { reject(new Error('Unable to execute "' + file + ' ' + args.join(' ') + '": ' + origErr.message)); }); }); } -function node(/*args... */) { +function node(/* args... */) { return spawn( process.execPath, _.toArray(arguments) diff --git a/scripts/generate/index.js b/scripts/generate/index.js index 937039fa2..c2f2f9f03 100644 --- a/scripts/generate/index.js +++ b/scripts/generate/index.js @@ -1,4 +1,4 @@ -/*jshint curly: false */ +/* jshint curly: false */ var async = require('async'); var fs = require('fs'); var spawn = require('../_spawn'); @@ -95,7 +95,7 @@ function dirRegex(dir, regexp) { function dirOpts(dir, opts) { opts = _.isArray(opts) ? opts : [opts]; return dirFilter(dir, function (name) { - return _.contains(opts, name); + return _.includes(opts, name); }); } @@ -206,7 +206,7 @@ function createArchive(branch) { spawnStep('mkdir', [dir], paths.root), spawnStep('git', ['archive', '--format', 'tar', '--output', tarball, branch, specPathInRepo], paths.esSrc), spawnStep('tar', ['-x', '-f', tarball, '-C', dir, '--strip-components', subDirCount]), - spawnStep('rm', [tarball]) + spawnStep('rm', [tarball]) ], done); }; } diff --git a/scripts/generate/js_api.js b/scripts/generate/js_api.js index f53750b71..2f9022144 100644 --- a/scripts/generate/js_api.js +++ b/scripts/generate/js_api.js @@ -87,7 +87,7 @@ module.exports = function (branch, done) { apiSpec = { actions: groups.normal || [], proxies: groups.proxies || [], - namespaces: _.unique(namespaces.sort(), true), + namespaces: _.uniq(namespaces.sort()), clientActionModifier: overrides.clientActionModifier }; @@ -170,12 +170,12 @@ module.exports = function (branch, done) { ); } - function __puke__transformSpec(spec) { + function __puke__transformSpec(spec) { // eslint-disable-line var actions = []; // itterate all of the specs within the file, should only be one _.each(spec, function (def, name) { - //camelcase the name + // camelcase the name name = _.map(name.split('.'), _.camelCase).join('.'); if (name === 'cat.aliases') { @@ -239,7 +239,7 @@ module.exports = function (branch, done) { urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':')); - return _.omit({ + return _.omitBy({ fmt: url.replace(urlParamRE, function (full, match) { return '<%=' + _.camelCase(match) + '%>'; }), @@ -251,8 +251,14 @@ module.exports = function (branch, done) { }); }); - if (urlSignatures.length !== _.unique(urlSignatures).length) { - throw new Error('Multiple URLS with the same signature detected for ' + spec.name + '\n' + _.pluck(urls, 'fmt').join('\n') + '\n'); + if (urlSignatures.length !== _.uniq(urlSignatures).length) { + throw new Error( + 'Multiple URLS with the same signature detected for ' + + spec.name + + '\n' + + _.map(urls, 'fmt').join('\n') + + '\n' + ); } if (urls.length > 1) { diff --git a/scripts/generate/overrides.js b/scripts/generate/overrides.js index 31c277c80..f3ee815eb 100644 --- a/scripts/generate/overrides.js +++ b/scripts/generate/overrides.js @@ -187,6 +187,7 @@ module.exports = [ version: '>=1.6.0', // strange indentation makes pretty api files +/* eslint-disable */ clientActionModifier: function (spec) { return require('../utils').merge(spec, { @@ -198,13 +199,15 @@ function (spec) { } }); } +/* eslint-enable */ }, { version: '>=2.0.0', aliases: { 'reindex.rethrottle': [ - '/_update_by_query/{task_id}/_rethrottle' + '/_update_by_query/{task_id}/_rethrottle', + '/_delete_by_query/{task_id}/_rethrottle' ] } } diff --git a/scripts/generate/templates/api_file.tmpl b/scripts/generate/templates/api_file.tmpl index a413da0f9..bd87d7f05 100644 --- a/scripts/generate/templates/api_file.tmpl +++ b/scripts/generate/templates/api_file.tmpl @@ -11,19 +11,19 @@ api._namespaces = <%= stringify(namespaces) %>;<% _.each(actions, function (action) { var namespace = action.location.split('.').shift(); - if (_.contains(namespaces, namespace)) { + if (_.includes(namespaces, namespace)) { _.pull(namespaces, namespace); %> api.<%= namespace %> = namespace();<% }%> -<%= partials.client_action(action) %><% +<%= _.trimEnd(partials.client_action(action)) %><% }); _.each(proxies, function (action) {%> -<%= partials.client_action_proxy(action) %><% +<%= _.trimEnd(partials.client_action_proxy(action)) %><% }); %> diff --git a/scripts/generate/templates/client_action.tmpl b/scripts/generate/templates/client_action.tmpl index 4a80b7f0f..81477174b 100644 --- a/scripts/generate/templates/client_action.tmpl +++ b/scripts/generate/templates/client_action.tmpl @@ -9,4 +9,4 @@ _.each(allParams, function(param, paramName) { %> } %><% }) %> */ -api<%= (location[0] === '[' ? '' : '.') + location %> = ca(<%= stringify(spec, true) %>); \ No newline at end of file +api<%= (location[0] === '[' ? '' : '.') + location %> = ca(<%= stringify(spec, true) %>); diff --git a/scripts/generate/templates/client_action_proxy.tmpl b/scripts/generate/templates/client_action_proxy.tmpl index f5dd98929..d708f1401 100644 --- a/scripts/generate/templates/client_action_proxy.tmpl +++ b/scripts/generate/templates/client_action_proxy.tmpl @@ -16,4 +16,4 @@ if (typeof transformBody === 'string') { %>, { } }<% } -%>); \ No newline at end of file +%>); diff --git a/scripts/generate/templates/index.js b/scripts/generate/templates/index.js index 0c3ef4cad..3a2f2ad23 100644 --- a/scripts/generate/templates/index.js +++ b/scripts/generate/templates/index.js @@ -14,7 +14,7 @@ var path = require('path'); */ function stringify(thing, pretty) { return (pretty ? JSON.stringify(thing, null, ' ') : JSON.stringify(thing)) - .replace(/\'/g, '\\\'') + .replace(/'/g, '\\\'') .replace(/\\?"/g, function (quote) { // replace external (unescaped) double quotes with single quotes return quote === '\\"' ? '"' : '\''; @@ -68,16 +68,16 @@ var templateGlobals = { paramType: function (type) { switch (type && type.toLowerCase ? type.toLowerCase() : 'any') { - case 'time': - return 'Date, Number'; - case 'any': - return 'Anything'; - case 'enum': - return 'String'; - case 'list': - return 'String, String[], Boolean'; - default: - return _.ucfirst(type); + case 'time': + return 'Date, Number'; + case 'any': + return 'Anything'; + case 'enum': + return 'String'; + case 'list': + return 'String, String[], Boolean'; + default: + return _.ucfirst(type); } }, diff --git a/scripts/generate/yaml_tests.js b/scripts/generate/yaml_tests.js index eed151ee1..093695b1a 100644 --- a/scripts/generate/yaml_tests.js +++ b/scripts/generate/yaml_tests.js @@ -51,8 +51,8 @@ module.exports = function (branch, done) { function writeTestIndex(done) { var file = fromRoot('test/integration/yaml_suite/index_' + _.snakeCase(branch) + '.js'); - fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');', 'utf8'); + fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8'); console.log(chalk.white.bold('wrote') + ' YAML index to', file); done(); } -}; \ No newline at end of file +}; diff --git a/scripts/release/bower.js b/scripts/release/bower.js index 3889bbbf7..3705c1dcb 100644 --- a/scripts/release/bower.js +++ b/scripts/release/bower.js @@ -42,4 +42,4 @@ async.series([ console.log('Error: ', err.message ? err.message : err); } } -}); \ No newline at end of file +}); diff --git a/src/elasticsearch.jquery.js b/src/elasticsearch.jquery.js index 6d6cce7f9..740a2ee1f 100644 --- a/src/elasticsearch.jquery.js +++ b/src/elasticsearch.jquery.js @@ -19,4 +19,4 @@ return new es.Client(config); }; -}(jQuery)); \ No newline at end of file +}(jQuery)); diff --git a/src/lib/apis/master.js b/src/lib/apis/master.js index 17202f02e..7a58870e4 100644 --- a/src/lib/apis/master.js +++ b/src/lib/apis/master.js @@ -1661,6 +1661,257 @@ api['delete'] = ca({ method: 'DELETE' }); +/** + * Perform a [deleteByQuery](https://www.elastic.co/guide/en/elasticsearch/plugins/master/plugins-reindex.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.analyzer - The analyzer to use for the query string + * @param {Boolean} params.analyzeWildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {String} [params.defaultOperator=OR] - The default operator for query string query (AND or OR) + * @param {String} params.df - The field to use as default where no field prefix is given in the query string + * @param {Boolean} params.explain - Specify whether to return detailed information about score computation as part of a hit + * @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return as part of a hit + * @param {String, String[], Boolean} params.fielddataFields - A comma-separated list of fields to return as the field data representation of a field for each hit + * @param {Number} params.from - Starting offset (default: 0) + * @param {Boolean} params.ignoreUnavailable - Whether specified concrete indices should be ignored when unavailable (missing or closed) + * @param {Boolean} params.allowNoIndices - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * @param {String} [params.conflicts=abort] - What to do when the delete-by-query hits version conflicts? + * @param {String} [params.expandWildcards=open] - Whether to expand wildcard expression to concrete indices that are open, closed or both. + * @param {Boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {Boolean} params.lowercaseExpandedTerms - Specify whether query terms should be lowercased + * @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random) + * @param {String} params.q - Query in the Lucene query string syntax + * @param {String, String[], Boolean} params.routing - A comma-separated list of specific routing values + * @param {Duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {String} params.searchType - Search operation type + * @param {Date, Number} params.searchTimeout - Explicit timeout for each search request. Defaults to no timeout. + * @param {Number} params.size - Number of hits to return (default: 10) + * @param {String, String[], Boolean} params.sort - A comma-separated list of : pairs + * @param {String, String[], Boolean} params._source - True or false to return the _source field or not, or a list of fields to return + * @param {String, String[], Boolean} params._sourceExclude - A list of fields to exclude from the returned _source field + * @param {String, String[], Boolean} params._sourceInclude - A list of fields to extract and return from the _source field + * @param {Number} params.terminateAfter - The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * @param {String, String[], Boolean} params.stats - Specific 'tag' of the request for logging and statistical purposes + * @param {String} params.suggestField - Specify which field to use for suggestions + * @param {String} [params.suggestMode=missing] - Specify suggest mode + * @param {Number} params.suggestSize - How many suggestions to return in response + * @param {Text} params.suggestText - The source text for which the suggestions should be returned + * @param {Date, Number} [params.timeout=1m] - Time each individual bulk request should wait for shards that are unavailable. + * @param {Boolean} params.trackScores - Whether to calculate and return scores even if they are not used for sorting + * @param {Boolean} params.version - Specify whether to return document version as part of a hit + * @param {Boolean} params.requestCache - Specify if request cache should be used for this request or not, defaults to index level setting + * @param {Boolean} params.refresh - Should the effected indexes be refreshed? + * @param {String} params.consistency - Explicit write consistency setting for the operation + * @param {Integer} params.scrollSize - Size on the scroll request powering the update_by_query + * @param {Boolean} params.waitForCompletion - Should the request should block until the delete-by-query is complete. + * @param {Float} params.requestsPerSecond - The throttle for this request in sub-requests per second. 0 means set no throttle. + * @param {String, String[], Boolean} params.index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {String, String[], Boolean} params.type - A comma-separated list of document types to search; leave empty to perform the operation on all types + */ +api.deleteByQuery = ca({ + params: { + analyzer: { + type: 'string' + }, + analyzeWildcard: { + type: 'boolean', + name: 'analyze_wildcard' + }, + defaultOperator: { + type: 'enum', + 'default': 'OR', + options: [ + 'AND', + 'OR' + ], + name: 'default_operator' + }, + df: { + type: 'string' + }, + explain: { + type: 'boolean' + }, + fields: { + type: 'list' + }, + fielddataFields: { + type: 'list', + name: 'fielddata_fields' + }, + from: { + type: 'number' + }, + ignoreUnavailable: { + type: 'boolean', + name: 'ignore_unavailable' + }, + allowNoIndices: { + type: 'boolean', + name: 'allow_no_indices' + }, + conflicts: { + type: 'enum', + 'default': 'abort', + options: [ + 'abort', + 'proceed' + ] + }, + expandWildcards: { + type: 'enum', + 'default': 'open', + options: [ + 'open', + 'closed', + 'none', + 'all' + ], + name: 'expand_wildcards' + }, + lenient: { + type: 'boolean' + }, + lowercaseExpandedTerms: { + type: 'boolean', + name: 'lowercase_expanded_terms' + }, + preference: { + type: 'string' + }, + q: { + type: 'string' + }, + routing: { + type: 'list' + }, + scroll: { + type: 'duration' + }, + searchType: { + type: 'enum', + options: [ + 'query_then_fetch', + 'dfs_query_then_fetch' + ], + name: 'search_type' + }, + searchTimeout: { + type: 'time', + name: 'search_timeout' + }, + size: { + type: 'number' + }, + sort: { + type: 'list' + }, + _source: { + type: 'list' + }, + _sourceExclude: { + type: 'list', + name: '_source_exclude' + }, + _sourceInclude: { + type: 'list', + name: '_source_include' + }, + terminateAfter: { + type: 'number', + name: 'terminate_after' + }, + stats: { + type: 'list' + }, + suggestField: { + type: 'string', + name: 'suggest_field' + }, + suggestMode: { + type: 'enum', + 'default': 'missing', + options: [ + 'missing', + 'popular', + 'always' + ], + name: 'suggest_mode' + }, + suggestSize: { + type: 'number', + name: 'suggest_size' + }, + suggestText: { + type: 'text', + name: 'suggest_text' + }, + timeout: { + type: 'time', + 'default': '1m' + }, + trackScores: { + type: 'boolean', + name: 'track_scores' + }, + version: { + type: 'boolean' + }, + requestCache: { + type: 'boolean', + name: 'request_cache' + }, + refresh: { + type: 'boolean' + }, + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + scrollSize: { + type: 'integer', + name: 'scroll_size' + }, + waitForCompletion: { + type: 'boolean', + 'default': false, + name: 'wait_for_completion' + }, + requestsPerSecond: { + type: 'float', + 'default': 0, + name: 'requests_per_second' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_delete_by_query', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_delete_by_query', + req: { + index: { + type: 'list' + } + } + } + ], + needBody: true, + method: 'POST' +}); + /** * Perform a [deleteScript](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request * diff --git a/src/lib/client.js b/src/lib/client.js index c29e2e4cb..51058dade 100755 --- a/src/lib/client.js +++ b/src/lib/client.js @@ -56,11 +56,11 @@ function Client(config) { this.transport = new Transport(config); - _.each(EsApiClient.prototype, function (Fn, prop) { + _.each(EsApiClient.prototype, _.bind(function (Fn, prop) { if (Fn.prototype instanceof clientAction.ApiNamespace) { this[prop] = new Fn(this.transport); } - }, this); + }, this)); delete this._namespaces; } diff --git a/src/lib/host.js b/src/lib/host.js index cdb2f10e7..08e6fa740 100644 --- a/src/lib/host.js +++ b/src/lib/host.js @@ -106,9 +106,9 @@ function Host(config, globalConfig) { delete config.auth; } - _.forOwn(config, function (val, prop) { + _.forOwn(config, _.bind(function (val, prop) { if (val != null) this[prop] = _.clone(val); - }, this); + }, this)); // make sure the query string is parsed if (this.query === null) { diff --git a/src/lib/logger.js b/src/lib/logger.js index 35f8f07e1..5732d7fed 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -64,7 +64,7 @@ LoggerAbstract.prototype.setupListeners = function (levels) { this.listeningLevels = []; - _.each(levels, function (level) { + _.each(levels, _.bind(function (level) { var fnName = 'on' + _.ucfirst(level); if (this.bound[fnName]) { this.listeningLevels.push(level); @@ -72,7 +72,7 @@ LoggerAbstract.prototype.setupListeners = function (levels) { } else { throw new Error('Unable to listen for level "' + level + '"'); } - }, this); + }, this)); }; /** @@ -83,9 +83,9 @@ LoggerAbstract.prototype.setupListeners = function (levels) { * @return {undefined} */ LoggerAbstract.prototype.cleanUpListeners = _.handler(function () { - _.each(this.listeningLevels, function (level) { + _.each(this.listeningLevels, _.bind(function (level) { this.log.removeListener(level, this.bound['on' + _.ucfirst(level)]); - }, this); + }, this)); }); /** diff --git a/src/lib/transport.js b/src/lib/transport.js index ba2ad07ee..452782372 100644 --- a/src/lib/transport.js +++ b/src/lib/transport.js @@ -274,7 +274,7 @@ Transport.prototype.request = function (params, cb) { if ( (!err || err instanceof errors.Serialization) && (status < 200 || status >= 300) - && (!params.ignore || !_.contains(params.ignore, status)) + && (!params.ignore || !_.includes(params.ignore, status)) ) { var errorMetadata = _.pick(params.req, ['path', 'query', 'body']); diff --git a/src/lib/utils.js b/src/lib/utils.js index 4996cee8b..c05d6d817 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -1,5 +1,4 @@ var path = require('path'); -var _ = require('lodash'); var nodeUtils = require('util'); /** @@ -10,16 +9,15 @@ var nodeUtils = require('util'); * @class utils * @static */ -var utils = _.extend({}, _, nodeUtils); -_ = utils; +var _ = require('lodash').assign({}, require('lodash'), nodeUtils); /** * Link to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2) * - * @method utils.joinPath + * @method _.joinPath * @type {function} */ -utils.joinPath = path.join; +_.joinPath = path.join; /** * Recursively merge two objects, walking into each object and concating arrays. If both to and from have a value at a @@ -31,7 +29,7 @@ utils.joinPath = path.join; * @param {Object} from - Object to pull changed from * @return {Object} - returns the modified to value */ -utils.deepMerge = function (to, from) { +_.deepMerge = function (to, from) { _.each(from, function (fromVal, key) { switch (typeof to[key]) { case 'undefined': @@ -42,7 +40,7 @@ utils.deepMerge = function (to, from) { to[key] = to[key].concat(from[key]); } else if (_.isPlainObject(to[key]) && _.isPlainObject(from[key])) { - utils.deepMerge(to[key], from[key]); + _.deepMerge(to[key], from[key]); } } }); @@ -67,7 +65,7 @@ _.each([ ], function (type) { var check = _['is' + type]; - utils['isArrayOf' + type + 's'] = function (arr) { + _['isArrayOf' + type + 's'] = function (arr) { // quick shallow check of arrays return _.isArray(arr) && _.every(arr.slice(0, 10), check); }; @@ -81,7 +79,7 @@ _.each([ * @param {string} word - The word to transform * @return {string} */ -utils.ucfirst = function (word) { +_.ucfirst = function (word) { return word[0].toUpperCase() + word.substring(1).toLowerCase(); }; @@ -142,7 +140,7 @@ function adjustWordCase(firstWordCap, otherWordsCap, sep) { * @param {String} string * @return {String} */ -utils.studlyCase = adjustWordCase(true, true, ''); +_.studlyCase = adjustWordCase(true, true, ''); /** * Transform a string into camelCase @@ -151,7 +149,7 @@ utils.studlyCase = adjustWordCase(true, true, ''); * @param {String} string * @return {String} */ -utils.camelCase = adjustWordCase(false, true, ''); +_.camelCase = adjustWordCase(false, true, ''); /** * Transform a string into snakeCase @@ -160,7 +158,7 @@ utils.camelCase = adjustWordCase(false, true, ''); * @param {String} string * @return {String} */ -utils.snakeCase = adjustWordCase(false, false, '_'); +_.snakeCase = adjustWordCase(false, false, '_'); /** * Lower-case a string, and return an empty string if any is not a string @@ -168,7 +166,7 @@ utils.snakeCase = adjustWordCase(false, false, '_'); * @param any {*} - Something or nothing * @returns {string} */ -utils.toLowerString = function (any) { +_.toLowerString = function (any) { if (any) { if (typeof any !== 'string') { any = any.toString(); @@ -185,7 +183,7 @@ utils.toLowerString = function (any) { * @param any {*} - Something or nothing * @returns {string} */ -utils.toUpperString = function (any) { +_.toUpperString = function (any) { if (any) { if (typeof any !== 'string') { any = any.toString(); @@ -203,7 +201,7 @@ utils.toUpperString = function (any) { * @param {*} val * @return {Boolean} */ -utils.isNumeric = function (val) { +_.isNumeric = function (val) { return typeof val !== 'object' && val - parseFloat(val) >= 0; }; @@ -217,7 +215,7 @@ var intervalRE = /^(\d+(?:\.\d+)?)(M|w|d|h|m|s|y|ms)$/; * @param {String} val * @return {Boolean} */ -utils.isInterval = function (val) { +_.isInterval = function (val) { return !!(val.match && val.match(intervalRE)); }; @@ -230,7 +228,7 @@ utils.isInterval = function (val) { * @param {Number} times - Times the string should be repeated * @return {String} */ -utils.repeat = function (what, times) { +_.repeat = function (what, times) { return (new Array(times + 1)).join(what); }; @@ -243,7 +241,7 @@ utils.repeat = function (what, times) { * @param [sliceIndex=0] {Integer} - The index that args should be sliced at, before feeding args to func * @returns {*} - the return value of func */ -utils.applyArgs = function (func, context, args, sliceIndex) { +_.applyArgs = function (func, context, args, sliceIndex) { sliceIndex = sliceIndex || 0; switch (args.length - sliceIndex) { case 0: @@ -442,4 +440,4 @@ _.now = function () { return (typeof Date.now === 'function') ? Date.now() : (new Date()).getTime(); }; -module.exports = utils; +module.exports = _; diff --git a/test/fixtures/keepalive.js b/test/fixtures/keepalive.js index c61ce7250..abbdee2d7 100644 --- a/test/fixtures/keepalive.js +++ b/test/fixtures/keepalive.js @@ -31,11 +31,11 @@ process.once('message', function (port) { var out = { socketCount: err || sockets.length, - remaining: _.where(sockets, { destroyed: true }).length - sockets.length, - timeouts: _.size(clock.timers) && _.pluck(clock.timers, 'func').map(String) + remaining: _.filter(sockets, { destroyed: true }).length - sockets.length, + timeouts: _.size(clock.timers) && _.map(clock.timers, 'func').map(String) }; clock.restore(); process.connected ? process.send(out) : console.log(out); }); -}); \ No newline at end of file +}); diff --git a/test/fixtures/keepalive_server.js b/test/fixtures/keepalive_server.js index 7f92981d1..e0d365878 100644 --- a/test/fixtures/keepalive_server.js +++ b/test/fixtures/keepalive_server.js @@ -13,4 +13,4 @@ var server = require('http').createServer(app); server.listen(function () { var port = server.address().port; process.connected ? process.send(port) : console.log(port); -}); \ No newline at end of file +}); diff --git a/test/integration/yaml_suite/client_manager.js b/test/integration/yaml_suite/client_manager.js index c4bad9cdb..4cc481a7b 100644 --- a/test/integration/yaml_suite/client_manager.js +++ b/test/integration/yaml_suite/client_manager.js @@ -55,7 +55,8 @@ module.exports = { function doCreateClient(options, cb) { if (typeof options === 'function') { - cb = options, options = {}; + cb = options; + options = {}; } var logConfig = {}; @@ -112,7 +113,7 @@ module.exports = { snapshot: '_all' }) .then(function (resp) { - return _.pluck(resp.snapshots, 'snapshot'); + return _.map(resp.snapshots, 'snapshot'); }, function () { return []; }) @@ -121,13 +122,13 @@ module.exports = { repository: repo, snapshot: snapshot }); - }, {concurrency: 1}) + }, { concurrency: 1 }) .then(function () { return client.snapshot.deleteRepository({ repository: repo }); }); - }, {concurrency: 1}) + }, { concurrency: 1 }) ]); }; diff --git a/test/integration/yaml_suite/run.js b/test/integration/yaml_suite/run.js index 1ee63484c..9ec43a994 100644 --- a/test/integration/yaml_suite/run.js +++ b/test/integration/yaml_suite/run.js @@ -37,4 +37,4 @@ module.exports = function (branch) { }); }); -}; \ No newline at end of file +}; diff --git a/test/integration/yaml_suite/yaml_doc.js b/test/integration/yaml_suite/yaml_doc.js index 18fcc7b99..cd7911536 100644 --- a/test/integration/yaml_suite/yaml_doc.js +++ b/test/integration/yaml_suite/yaml_doc.js @@ -9,7 +9,7 @@ */ module.exports = YamlDoc; -var _ = require('../../../src/lib/utils'); +var _ = require('lodash'); var expect = require('expect.js'); var clientManager = require('./client_manager'); var inspect = require('util').inspect; @@ -26,10 +26,10 @@ var ES_VERSION = null; var versionExp = '((?:\\d+\\.){0,2}\\d+)(?:[\\.\\-]\\w+)?|'; // match all whitespace within a "regexp" match arg -var reWhitespace_RE = /\s+/g; +var reWhitespaceRE = /\s+/g; // match all comments within a "regexp" match arg -var reComments_RE = /([\S\s]?)#[^\n]*\n/g; +var reCommentsRE = /([\S\s]?)#[^\n]*\n/g; /** * Regular Expression to extract a version number from a string @@ -200,7 +200,7 @@ YamlDoc.prototype = { // creates [ [ {name:"", args:"" }, ... ], ... ] // from [ {name:args, name:args}, {name:args} ] var actionSets = _.map(config, function (set) { - return _.map(_.pairs(set), function (pair) { + return _.map(_.toPairs(set), function (pair) { return { name: pair[0], args: pair[1] }; }); }); @@ -356,34 +356,34 @@ YamlDoc.prototype = { // resolve the catch arg to a value used for matching once the request is complete switch (args.catch) { - case void 0: - catcher = null; - break; - case 'missing': - catcher = 404; - break; - case 'conflict': - catcher = 409; - break; - case 'forbidden': - catcher = 403; - break; - case 'request_timeout': - catcher = 408; - break; - case 'request': - catcher = /.*/; - break; - case 'param': - catcher = TypeError; - break; - default: - catcher = args.catch.match(/^\/(.*)\/$/); - if (catcher) { - catcher = new RegExp(catcher[1]); - } else { - return done(new TypeError('unsupported catch type ' + args.catch)); - } + case void 0: + catcher = null; + break; + case 'missing': + catcher = 404; + break; + case 'conflict': + catcher = 409; + break; + case 'forbidden': + catcher = 403; + break; + case 'request_timeout': + catcher = 408; + break; + case 'request': + catcher = /.*/; + break; + case 'param': + catcher = TypeError; + break; + default: + catcher = args.catch.match(/^\/(.*)\/$/); + if (catcher) { + catcher = new RegExp(catcher[1]); + } else { + return done(new TypeError('unsupported catch type ' + args.catch)); + } } delete args.catch; @@ -407,7 +407,7 @@ YamlDoc.prototype = { var clientAction = this.get(clientActionName, client); _.assign(inputParams, args[action]); - var params = _.transform(inputParams, function (params, val, name) { + var params = _.transform(inputParams, _.bind(function (params, val, name) { var camelName = _.camelCase(name); // search through the params and url peices to find this param name @@ -437,18 +437,18 @@ YamlDoc.prototype = { }.bind(this); transformObject(params, val, paramName); - }, {}, this); + }, this), {}); expect(clientAction || clientActionName).to.be.a('function'); - if (_.isNumeric(catcher)) { + if (!isNaN(parseFloat(catcher))) { params.ignore = _.union(params.ignore || [], [catcher]); catcher = null; } var timeoutId; - var cb = _.bind(function (error, body) { + var cb = _.bind(function (error, body) { this._last_requests_response = body; clearTimeout(timeoutId); @@ -494,9 +494,9 @@ YamlDoc.prototype = { * @return {undefined} */ do_set: function (args) { - _.forOwn(args, function (name, path) { + _.forOwn(args, _.bind(function (name, path) { this._stash[name] = this.get(path); - }, this); + }, this)); }, /** @@ -578,7 +578,7 @@ YamlDoc.prototype = { } }); - _.forOwn(args, function (match, path) { + _.forOwn(args, _.bind(function (match, path) { var origMatch = match; var maybeRE = false; @@ -588,7 +588,7 @@ YamlDoc.prototype = { // convert the matcher into a compatible string for building a regexp maybeRE = match // replace comments, but allow the # to be escaped like \# - .replace(reComments_RE, function (match, prevChar) { + .replace(reCommentsRE, function (match, prevChar) { if (prevChar === '\\') { return match; } else { @@ -597,7 +597,7 @@ YamlDoc.prototype = { }) // remove all whitespace from the expression, all meaningful // whitespace is represented with \s - .replace(reWhitespace_RE, ''); + .replace(reWhitespaceRE, ''); var startsWithSlash = maybeRE[0] === '/'; var endsWithSlash = maybeRE[maybeRE.length - 1] === '/'; @@ -645,7 +645,7 @@ YamlDoc.prototype = { throw new Error(msg.join('\n')); } - }, this); + }, this)); }, /** @@ -655,9 +655,9 @@ YamlDoc.prototype = { * @return {undefined} */ do_lt: function (args) { - _.forOwn(args, function (num, path) { + _.forOwn(args, _.bind(function (num, path) { expect(this.get(path)).to.be.below(num, 'path: ' + path); - }, this); + }, this)); }, /** @@ -667,9 +667,9 @@ YamlDoc.prototype = { * @return {undefined} */ do_lte: function (args) { - _.forOwn(args, function (num, path) { + _.forOwn(args, _.bind(function (num, path) { expect(this.get(path) <= num).to.be.ok('path: ' + path); - }, this); + }, this)); }, /** @@ -679,9 +679,9 @@ YamlDoc.prototype = { * @return {undefined} */ do_gt: function (args) { - _.forOwn(args, function (num, path) { + _.forOwn(args, _.bind(function (num, path) { expect(this.get(path)).to.be.above(num, 'path: ' + path); - }, this); + }, this)); }, /** @@ -691,9 +691,9 @@ YamlDoc.prototype = { * @return {undefined} */ do_gte: function (args) { - _.forOwn(args, function (num, path) { + _.forOwn(args, _.bind(function (num, path) { expect(this.get(path) >= num).to.be.ok('path: ' + path); - }, this); + }, this)); }, /** @@ -704,8 +704,8 @@ YamlDoc.prototype = { * @return {undefined} */ do_length: function (args) { - _.forOwn(args, function (len, path) { + _.forOwn(args, _.bind(function (len, path) { expect(_.size(this.get(path))).to.eql(len, 'path: ' + path); - }, this); + }, this)); } }; diff --git a/test/integration/yaml_suite/yaml_file.js b/test/integration/yaml_suite/yaml_file.js index 1035a37ec..b96529fc6 100644 --- a/test/integration/yaml_suite/yaml_file.js +++ b/test/integration/yaml_suite/yaml_file.js @@ -19,7 +19,7 @@ function YamlFile(filename, docs) { describe(filename, function () { file.docs = _.map(docs, function (doc) { - doc = new YamlDoc(doc, file); + doc = new YamlDoc(doc, file); if (doc.description === 'setup') { beforeEach(/* doc */function (done) { async.series(doc.getActionsRunners(), done); diff --git a/test/mocks/browser_http.js b/test/mocks/browser_http.js index edbbbf448..9b42d48ff 100644 --- a/test/mocks/browser_http.js +++ b/test/mocks/browser_http.js @@ -1,4 +1,4 @@ - +/* eslint-disable */ ////////////// /// Extended version of: /// https://github.com/philikon/MockHttpRequest/ diff --git a/test/mocks/browser_server.js b/test/mocks/browser_server.js index 7c4d0db59..3d0010519 100644 --- a/test/mocks/browser_server.js +++ b/test/mocks/browser_server.js @@ -57,15 +57,15 @@ var mockNock = module.exports = function (url) { req.status = status; req.body = body; switch (typeof req.body) { - case 'string': - case 'number': - break; - default: - try { - req.body = req.body && JSON.stringify(req.body); - } catch (e) { - req.body = req.body; - } + case 'string': + case 'number': + break; + default: + try { + req.body = req.body && JSON.stringify(req.body); + } catch (e) { + req.body = req.body; + } } interceptors.push(req); return mockNock(url); @@ -80,4 +80,4 @@ mockNock.done = function () { if (interceptors.length) { throw new Error('Some interceptors were not called: ' + JSON.stringify(interceptors)); } -}; \ No newline at end of file +}; diff --git a/test/mocks/incomming_message.js b/test/mocks/incomming_message.js index 2cca8809d..ce29326cd 100644 --- a/test/mocks/incomming_message.js +++ b/test/mocks/incomming_message.js @@ -32,4 +32,4 @@ util.inherits(MockIncommingMessage, Readable); * } * incom.push(null); * }); - */ \ No newline at end of file + */ diff --git a/test/mocks/writable_stream.js b/test/mocks/writable_stream.js index e20239af0..1907b233c 100644 --- a/test/mocks/writable_stream.js +++ b/test/mocks/writable_stream.js @@ -75,4 +75,4 @@ if (Writable) { // There is no shutdown() for files. MockWritableStream.prototype.destroySoon = MockWritableStream.prototype.end; -} \ No newline at end of file +} diff --git a/test/unit/browser_builds/angular.js b/test/unit/browser_builds/angular.js index 559b09edb..aa021498b 100644 --- a/test/unit/browser_builds/angular.js +++ b/test/unit/browser_builds/angular.js @@ -1,3 +1,4 @@ +/* global angular */ var _ = require('lodash'); var expect = require('expect.js'); var Promise = require('bluebird'); @@ -82,4 +83,4 @@ describe('Angular esFactory', function () { return prom; }); }); -}); \ No newline at end of file +}); diff --git a/test/unit/browser_builds/generic.js b/test/unit/browser_builds/generic.js index 4deec0163..e523fe7c9 100644 --- a/test/unit/browser_builds/generic.js +++ b/test/unit/browser_builds/generic.js @@ -17,4 +17,4 @@ describe('elasticsearch namespace', function () { expect(client.transport).to.be.a(es.Transport); client.close(); }); -}); \ No newline at end of file +}); diff --git a/test/unit/browser_builds/jquery.js b/test/unit/browser_builds/jquery.js index 0a0e3724e..11e04ad63 100644 --- a/test/unit/browser_builds/jquery.js +++ b/test/unit/browser_builds/jquery.js @@ -1,3 +1,4 @@ +/* global $ */ var expect = require('expect.js'); var Transport = require('../../../src/lib/transport'); @@ -16,4 +17,4 @@ describe('jQuery.es namespace', function () { expect(client.transport).to.be.a($.es.Transport); client.close(); }); -}); \ No newline at end of file +}); diff --git a/test/unit/buffer_flush_tests.js b/test/unit/buffer_flush_tests.js index 7023c73ff..4d61a7ed8 100644 --- a/test/unit/buffer_flush_tests.js +++ b/test/unit/buffer_flush_tests.js @@ -57,4 +57,4 @@ module.exports = function (makeLogger) { }); } }); -}; \ No newline at end of file +}; diff --git a/test/unit/coverage.js b/test/unit/coverage.js index 63b4fbd9b..a59557d9d 100644 --- a/test/unit/coverage.js +++ b/test/unit/coverage.js @@ -1,5 +1,5 @@ -var blanket = require("blanket")({ +var blanket = require('blanket')({ pattern: require('path').join(__dirname, '../../src') }); -require('./index'); \ No newline at end of file +require('./index'); diff --git a/test/unit/generic_logger_tests.js b/test/unit/generic_logger_tests.js index f9f3ed834..42f788ceb 100644 --- a/test/unit/generic_logger_tests.js +++ b/test/unit/generic_logger_tests.js @@ -234,4 +234,4 @@ module.exports = function (makeLogger) { expect(logger.write.callCount).to.eql(1); }); }); -}; \ No newline at end of file +}; diff --git a/test/unit/index.js b/test/unit/index.js index 8f437dc25..ed696a9c4 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -3,4 +3,4 @@ require('bluebird').longStackTraces(); var specDir = __dirname + '/specs'; require('fs').readdirSync(specDir).forEach(function (file) { require(specDir + '/' + file); -}); \ No newline at end of file +}); diff --git a/test/unit/specs/abstract_logger.js b/test/unit/specs/abstract_logger.js index 45158a9ba..577c0fc9f 100644 --- a/test/unit/specs/abstract_logger.js +++ b/test/unit/specs/abstract_logger.js @@ -32,4 +32,4 @@ describe('Logger Abstract', function () { require('../generic_logger_tests')(makeLogger); -}); \ No newline at end of file +}); diff --git a/test/unit/specs/client.js b/test/unit/specs/client.js index 4d7c59275..0be3338f5 100644 --- a/test/unit/specs/client.js +++ b/test/unit/specs/client.js @@ -68,7 +68,7 @@ describe('Client instances creation', function () { } util.inherits(NullStream, stream.Writable); - NullStream.prototype._write = function(/* chunk, encoding, next */) { + NullStream.prototype._write = function (/* chunk, encoding, next */) { done(); }; diff --git a/test/unit/specs/client_action.js b/test/unit/specs/client_action.js index 578432a6f..6dd71002d 100644 --- a/test/unit/specs/client_action.js +++ b/test/unit/specs/client_action.js @@ -195,7 +195,7 @@ describe('Client Action runner', function () { it('rejects array', function (done) { action({ one: ['one'], - two: [ 1304 ] + two: [1304] }, function (err, params) { expect(err).to.be.a(TypeError); done(); @@ -629,7 +629,7 @@ describe('Client Action runner', function () { method: 'POST' }); - action({method: 'get'}, function (err, params) { + action({ method: 'get' }, function (err, params) { expect(params.method).to.be('GET'); done(); }); diff --git a/test/unit/specs/connection_abstract.js b/test/unit/specs/connection_abstract.js index a1e8ec88b..f9b67ff33 100644 --- a/test/unit/specs/connection_abstract.js +++ b/test/unit/specs/connection_abstract.js @@ -17,11 +17,11 @@ describe('Connection Abstract', function () { it('requires a valid host', function () { expect(function () { - new ConnectionAbstract(); + var conn = new ConnectionAbstract(); }).to.throwError(TypeError); expect(function () { - new ConnectionAbstract({}); + var conn = new ConnectionAbstract({}); }).to.throwError(TypeError); }); @@ -81,7 +81,6 @@ describe('Connection Abstract', function () { it('calls it\'s own request method', function () { var conn = new ConnectionAbstract(host); - var football = {}; stub(conn, 'request'); conn.ping(); expect(conn.request.callCount).to.eql(1); diff --git a/test/unit/specs/connection_pool.js b/test/unit/specs/connection_pool.js index 76df25378..0b4c8b5c3 100644 --- a/test/unit/specs/connection_pool.js +++ b/test/unit/specs/connection_pool.js @@ -1,6 +1,5 @@ var ConnectionPool = require('../../../src/lib/connection_pool'); var Host = require('../../../src/lib/host'); -var errors = require('../../../src/lib/errors'); var ConnectionAbstract = require('../../../src/lib/connection'); var _ = require('lodash'); var EventEmitter = require('events').EventEmitter; @@ -121,7 +120,7 @@ describe('Connection Pool', function () { }); it('detects if the selector is not async', function (done) { - pool.selector = function (list) { + pool.selector = function () { expect(arguments.length).to.be(1); }; @@ -149,11 +148,11 @@ describe('Connection Pool', function () { }); it('should catch errors in sync selectors', function (done) { - pool.selector = function (list) { + pool.selector = function () { return JSON.notAMethod(); }; - pool.select(function (err, selection) { + pool.select(function (err) { expect(err).be.an(Error); done(); }); @@ -297,7 +296,8 @@ describe('Connection Pool', function () { var result = pool.getConnections(); expect(result.length).to.be(1000); expect(_.reduce(result, function (sum, num) { - return sum += num; + sum += num + return sum; }, 0)).to.eql(499500); }); }); diff --git a/test/unit/specs/host.js b/test/unit/specs/host.js index d02444b1a..44f432455 100644 --- a/test/unit/specs/host.js +++ b/test/unit/specs/host.js @@ -32,7 +32,7 @@ describe('Host class', function () { }); it('accepts a string for query', function () { - var host = new Host({ query: 'beep=boop'}); + var host = new Host({ query: 'beep=boop' }); expect(host.query).to.eql({ beep: 'boop' @@ -157,14 +157,14 @@ describe('Host class', function () { var host = new Host(); host.path = 'prefix'; - expect(host.makeUrl({ path: '/this and that'})) + expect(host.makeUrl({ path: '/this and that' })) .to.be('http://localhost:9200/prefix/this and that'); }); it('does not try to prevent double forward-slashes', function () { var host = new Host({ path: 'prefix/' }); - expect(host.makeUrl({ path: '/this and that'})) + expect(host.makeUrl({ path: '/this and that' })) .to.be('http://localhost:9200/prefix//this and that'); }); @@ -175,7 +175,7 @@ describe('Host class', function () { host = new Host({ host: 'john', port: 80 }); expect(host.makeUrl()).to.be('http://john/'); - host = new Host({ host: 'italy', path: '/pie', auth: 'user:pass'}); + host = new Host({ host: 'italy', path: '/pie', auth: 'user:pass' }); expect(host.makeUrl()).to.be('http://italy:9200/pie'); }); diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index c9ee86f2b..c88f3577e 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -324,7 +324,7 @@ describe('Http Connector', function () { zlib.gzip(body, function (err, compressedBody) { server .get('/users/1') - .reply(200, compressedBody, {'Content-Encoding': 'gzip'}); + .reply(200, compressedBody, { 'Content-Encoding': 'gzip' }); con.request({ method: 'GET', @@ -350,7 +350,7 @@ describe('Http Connector', function () { zlib.deflate(body, function (err, compressedBody) { server .get('/users/1') - .reply(200, compressedBody, {'Content-Encoding': 'deflate'}); + .reply(200, compressedBody, { 'Content-Encoding': 'deflate' }); con.request({ method: 'GET', @@ -371,7 +371,7 @@ describe('Http Connector', function () { var body = 'blah'; server .get('/users/1') - .reply(200, body, {'Content-Encoding': 'gzip'}); + .reply(200, body, { 'Content-Encoding': 'gzip' }); con.request({ method: 'GET', diff --git a/test/unit/specs/json_serializer.js b/test/unit/specs/json_serializer.js index 0ec2f9e5c..9a876ba0f 100644 --- a/test/unit/specs/json_serializer.js +++ b/test/unit/specs/json_serializer.js @@ -97,4 +97,4 @@ describe('JSON serializer', function () { }).to.throwError(); }); }); -}); \ No newline at end of file +}); diff --git a/test/unit/specs/log.js b/test/unit/specs/log.js index 8976c01bd..44e7fa28d 100644 --- a/test/unit/specs/log.js +++ b/test/unit/specs/log.js @@ -141,7 +141,7 @@ describe('Log class', function () { log.emit = function (eventName) { call = { - event : eventName, + event: eventName, args: Array.prototype.slice.call(arguments, 1) }; }; @@ -221,7 +221,7 @@ describe('Log class', function () { }); it('accepts an array of output config objects', function () { - var log = new Log({ log: [{ level: 'error' }, { level: 'trace'}] }); + var log = new Log({ log: [{ level: 'error' }, { level: 'trace' }] }); expect(log.listenerCount('error')).to.eql(2); expect(log.listenerCount('warning')).to.eql(1); expect(log.listenerCount('info')).to.eql(1); diff --git a/test/unit/specs/nodes_to_host_callback.js b/test/unit/specs/nodes_to_host_callback.js index 2f52b4bd3..c8830f9c4 100644 --- a/test/unit/specs/nodes_to_host_callback.js +++ b/test/unit/specs/nodes_to_host_callback.js @@ -61,7 +61,6 @@ describe('Nodes to host callback', function () { }); - it('ignores hosts that don\'t have an http_host property', function () { var hosts = callback({ node_id: { @@ -74,7 +73,7 @@ describe('Nodes to host callback', function () { it('throws an error when the host property is not formatted properly', function () { expect(function () { - var hosts = callback({ + callback({ node_id: { http_address: 'not actually an http host' } diff --git a/test/unit/specs/transport.js b/test/unit/specs/transport.js index 39c15fca6..f7aaba374 100644 --- a/test/unit/specs/transport.js +++ b/test/unit/specs/transport.js @@ -1,7 +1,6 @@ var Transport = require('../../../src/lib/transport'); var Host = require('../../../src/lib/host'); var errors = require('../../../src/lib/errors'); -var Promise = require('bluebird'); var sinon = require('sinon'); var expect = require('expect.js'); @@ -354,10 +353,10 @@ describe('Transport Class', function () { }); it('logs an error if nodes to host throws one', function (done) { - trans.nodesToHostCallback = function (nodes) { + trans.nodesToHostCallback = function () { throw new Error('I failed'); }; - trans.log.error = function (err) { + trans.log.error = function () { done(); }; trans.sniff(); @@ -408,7 +407,7 @@ describe('Transport Class', function () { }); }); it('passed back the full server response', function (done) { - trans.sniff(function (err, resp, status) { + trans.sniff(function (err, resp) { expect(resp.ok).to.eql(true); expect(resp.cluster_name).to.eql('clustername'); done(); @@ -501,7 +500,7 @@ describe('Transport Class', function () { }); var conn = getConnection(trans); var body = [ - { _id: 'simple body'}, + { _id: 'simple body' }, { name: 'ഢധയമബ' } ]; @@ -526,7 +525,7 @@ describe('Transport Class', function () { var trans = new Transport({ hosts: 'localhost' }); - var conn = getConnection(trans); + getConnection(trans); var body = { _id: 'circular body' }; @@ -560,7 +559,7 @@ describe('Transport Class', function () { } }); - trans.request({}, function (err, body, status) { + trans.request({}, function (err) { expect(err.message).to.eql('I am broken'); }); }); @@ -574,7 +573,7 @@ describe('Transport Class', function () { } }); - trans.request({}, function (err, body, status) { + trans.request({}, function (err) { expect(err.message).to.eql('I am broken'); }); }); @@ -638,7 +637,6 @@ describe('Transport Class', function () { }); - describe('return value', function () { it('returns an object with an abort() method when a callback is sent', function () { var tran = new Transport(); @@ -681,7 +679,7 @@ describe('Transport Class', function () { expect(process.domain).to.be(null); var tran = new Transport(); shortCircuitRequest(tran); - tran.request({}, function(err, result, status) { + tran.request({}, function () { expect(process.domain).to.be(null); }); }); @@ -689,12 +687,12 @@ describe('Transport Class', function () { it('binds the callback to the correct domain', function () { expect(process.domain).to.be(null); var domain = require('domain').create(); - domain.run(function() { + domain.run(function () { var tran = new Transport(); shortCircuitRequest(tran); expect(process.domain).not.to.be(null); var startingDomain = process.domain - tran.request({}, function(err, result, status) { + tran.request({}, function () { expect(process.domain).not.to.be(null); expect(process.domain).to.be(startingDomain); process.domain.exit(); @@ -758,7 +756,6 @@ describe('Transport Class', function () { var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout'); stub.autoRelease(clock); var tran = new Transport({}); - var err; var prom = tran.request({}); // disregard promise, prevent bluebird's warnings @@ -776,7 +773,6 @@ describe('Transport Class', function () { var tran = new Transport({ requestTimeout: 5000 }); - var err; var prom = tran.request({}); // disregard promise, prevent bluebird's warnings @@ -799,7 +795,7 @@ describe('Transport Class', function () { tran.request({ requestTimeout: falsy - }, function (_err) {}); + }, function () {}); expect(_.size(clock.timers)).to.eql(0); }); diff --git a/test/unit/specs/utils.js b/test/unit/specs/utils.js index fe1b73d9d..0c6f6fcfc 100644 --- a/test/unit/specs/utils.js +++ b/test/unit/specs/utils.js @@ -32,7 +32,7 @@ describe('Utils', function () { } }, function (thing, name) { - describe('#isArrayOf' + name, function (test) { + describe('#isArrayOf' + name, function () { it('likes arrays of ' + name, function () { expect(_['isArrayOf' + name + 's'](thing.is)).to.be(true); }); @@ -54,7 +54,6 @@ describe('Utils', function () { expect(_.isNumeric(0)).to.be(true); expect(_.isNumeric(32)).to.be(true); expect(_.isNumeric('040')).to.be(true); - expect(_.isNumeric(0144)).to.be(true); expect(_.isNumeric('0xFF')).to.be(true); expect(_.isNumeric(0xFFF)).to.be(true); }); @@ -196,7 +195,7 @@ describe('Utils', function () { }); it('sorta kinda works on objects', function () { - expect(_.toLowerString({a: 'thing'})).to.eql('[object object]'); + expect(_.toLowerString({ a: 'thing' })).to.eql('[object object]'); }); }); @@ -216,7 +215,7 @@ describe('Utils', function () { }); it('sorta kinda works on objects', function () { - expect(_.toUpperString({a: 'thing'})).to.eql('[OBJECT OBJECT]'); + expect(_.toUpperString({ a: 'thing' })).to.eql('[OBJECT OBJECT]'); }); }); @@ -268,7 +267,7 @@ describe('Utils', function () { foo: ['bax', 'boz'] } }; - _.deepMerge(obj, { bax: { foo: ['poo'] }}); + _.deepMerge(obj, { bax: { foo: ['poo'] } }); expect(obj.bax.foo).to.have.length(3); }); @@ -282,7 +281,7 @@ describe('Utils', function () { expect(out).to.not.be(inp); }); it('accepts a primitive value and calls the the transform function', function (done) { - var out = _.createArray('str', function (val) { + _.createArray('str', function (val) { expect(val).to.be('str'); done(); }); diff --git a/test/unit/specs/yaml_test_reader.js b/test/unit/specs/yaml_test_reader.js index 0c241949a..4e101c1df 100644 --- a/test/unit/specs/yaml_test_reader.js +++ b/test/unit/specs/yaml_test_reader.js @@ -19,4 +19,4 @@ describe('Yaml Test Reader', function () { expect(compare('0.90 - 1.2', '1.4')).to.be(false); }); }); -}); \ No newline at end of file +}); diff --git a/test/utils/auto_release_stub.js b/test/utils/auto_release_stub.js index ce66cbf02..7ae531de7 100644 --- a/test/utils/auto_release_stub.js +++ b/test/utils/auto_release_stub.js @@ -18,4 +18,4 @@ exports.make = function () { }; return stubber; -}; \ No newline at end of file +}; diff --git a/test/utils/expect_sub_object.js b/test/utils/expect_sub_object.js index 57b6b4276..013be8a5b 100644 --- a/test/utils/expect_sub_object.js +++ b/test/utils/expect_sub_object.js @@ -9,4 +9,4 @@ module.exports = function expectSubObject(obj, subObj) { expect(obj).property(prop, val); } }); -}; \ No newline at end of file +}; diff --git a/test/utils/jenkins-reporter.js b/test/utils/jenkins-reporter.js index 818e30bb6..48c5de673 100644 --- a/test/utils/jenkins-reporter.js +++ b/test/utils/jenkins-reporter.js @@ -22,7 +22,7 @@ var log = (function () { } locked(str); }; -})(); +}()); var integration = _.find(process.argv, function (arg) { return arg.indexOf('test/integration') > -1; }); var unit = _.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; }); @@ -86,7 +86,7 @@ function JenkinsReporter(runner) { stack.shift(); }); - runner.on('fail', function (test, err) { + runner.on('fail', function (test) { if ('hook' === test.type) { runner.emit('test end', test); } diff --git a/test/utils/make_j_unit_xml.js b/test/utils/make_j_unit_xml.js index 01cf06c04..6474afa12 100644 --- a/test/utils/make_j_unit_xml.js +++ b/test/utils/make_j_unit_xml.js @@ -41,7 +41,7 @@ function makeJUnitXml(runnerName, testDetails) { timestamp: moment(suiteInfo.start).toJSON(), hostname: 'localhost', tests: (suiteInfo.results && suiteInfo.results.length) || 0, - failures: _.where(suiteInfo.results, {pass: false}).length, + failures: _.filter(suiteInfo.results, { pass: false }).length, errors: 0, time: suiteInfo.time / 1000 }); @@ -89,7 +89,7 @@ function makeJUnitXml(runnerName, testDetails) { giveOutput(suite, suiteInfo); }); - return suites.toString({ pretty: true}); + return suites.toString({ pretty: true }); } function giveOutput(el, info) { @@ -103,4 +103,4 @@ function giveOutput(el, info) { if (err) { el.ele('system-err', {}).cdata(chalk.stripColor(err)); } -} \ No newline at end of file +} diff --git a/test/utils/server.js b/test/utils/server.js index 0ebe2894b..bb1770e04 100644 --- a/test/utils/server.js +++ b/test/utils/server.js @@ -1,3 +1,4 @@ +/* eslint-disable import/no-unresolved */ var express = require('express'); var http = require('http'); var fs = require('fs'); @@ -31,6 +32,8 @@ testFiles.build = fs.readdirSync(browserBuildsDir) if (file.substr(-3) === '.js') { return browserBuildsDir + '/' + file; } + + return null }) .filter(Boolean); @@ -73,7 +76,7 @@ function bundleTests(name) { // create a route that just rends a specific file (like a symlink or something) function sendFile(file) { - return function (req, res, next) { + return function (req, res) { res.sendfile(file); }; } @@ -111,4 +114,4 @@ app http.createServer(app).listen(8000, function () { console.log('listening on port 8000'); -}); \ No newline at end of file +}); diff --git a/test/utils/slk.js b/test/utils/slk.js index e2764ba8b..0b95154c4 100644 --- a/test/utils/slk.js +++ b/test/utils/slk.js @@ -3,4 +3,4 @@ module.exports = JSON.parse(new Buffer( 'eyJ1c2VyIjoiZWxhc3RpY3NlYXJjaC1qcyIsImtleSI6IjI0ZjQ5ZTA3LWQ4MmYtNDA2Ny04NTRlLWQ4MTVlYmQxNWU0NiJ9', 'base64' -).toString('utf8')); \ No newline at end of file +).toString('utf8'));