From 3bb12129ef87cae2a4b81abdefe11504e79b158a Mon Sep 17 00:00:00 2001 From: dthree Date: Sun, 21 Jun 2015 11:31:15 -0700 Subject: [PATCH] linting --- lib/vantage.js | 168 ++++++++++++++++++++++++------------------------- package.json | 12 +++- 2 files changed, 95 insertions(+), 85 deletions(-) mode change 100644 => 100755 package.json diff --git a/lib/vantage.js b/lib/vantage.js index f8d886a..6173354 100755 --- a/lib/vantage.js +++ b/lib/vantage.js @@ -3,16 +3,16 @@ * Module dependencies. */ -var _ = require('lodash') - , EventEmitter = require('events').EventEmitter - , Command = require('./command') - , VantageServer = require('./server') - , VantageClient = require('./client') - , VantageUtil = require('./util') - , intercept = require('./intercept') - , commons = require('./vantage-commons') - , inquirer = require('inquirer') - , minimist = require('minimist') +var _ = require("lodash") + , EventEmitter = require("events").EventEmitter + , Command = require("./command") + , VantageServer = require("./server") + , VantageClient = require("./client") + , VantageUtil = require("./util") + , intercept = require("./intercept") + , commons = require("./vantage-commons") + , inquirer = require("inquirer") + , minimist = require("minimist") ; /** @@ -46,7 +46,7 @@ function Vantage() { // Program version // Exposed through vantage.version(str); - this._version = ''; + this._version = ""; // Registered `vantage.command` commands and // their options. @@ -54,12 +54,12 @@ function Vantage() { // Prompt delimiter. // Exposed through vantage.delimiter(str). - this._delimiter = 'local~$'; - this._origdelimiter = 'local~$'; + this._delimiter = "local~$"; + this._origdelimiter = "local~$"; // Prompt Command History - // Histctr moves based on number of times 'up' (+= ctr) - // or 'down' (-= ctr) was pressed in traversing + // Histctr moves based on number of times "up" (+= ctr) + // or "down" (-= ctr) was pressed in traversing // command history. this._hist = []; this._histCtr = 0; @@ -181,8 +181,8 @@ vantage.version = function(version) { vantage.delimiter = function(str) { var slf = this; - this._delimiter = String(str).trim() + ' '; - this._origdelimiter = String(str).trim() + ' '; + this._delimiter = String(str).trim() + " "; + this._origdelimiter = String(str).trim() + " "; inquirer.prompt.prompts.input.prototype.prefix = function() { return slf._delimiter; } @@ -201,7 +201,7 @@ vantage.delimiter = function(str) { vantage._tempDelimiter = function(str) { var self = this; - this._delimiter = String(str || '').trim() + ' '; + this._delimiter = String(str || "").trim() + " "; inquirer.prompt.prompts.input.prototype.prefix = function() { return self._delimiter; } @@ -221,19 +221,19 @@ vantage._tempDelimiter = function(str) { */ vantage.is = function(role, setter) { - this._isClient = (role == 'client' && setter !== undefined) ? setter : this._isClient; - this._isServer = (role == 'server' && setter !== undefined) ? setter : this._isServer; - this._isTerminable = (role == 'terminable' && setter !== undefined) ? setter : this._isTerminable; + this._isClient = (role == "client" && setter !== undefined) ? setter : this._isClient; + this._isServer = (role == "server" && setter !== undefined) ? setter : this._isServer; + this._isTerminable = (role == "terminable" && setter !== undefined) ? setter : this._isTerminable; var response = - (role == 'terminable' && this._isTerminable) ? true : - (role == 'local' && (!this._isServer && !this._isClient)) ? true : - (role == 'local' && (this._isClient && this._isTerminable)) ? true : - (role == 'local') ? false : - (role == 'proxy' && this._isClient && this._isServer) ? true : - (role == 'proxy') ? false : - (role == 'client') ? this._isClient : - (role == 'server') ? this._isServer : false; + (role == "terminable" && this._isTerminable) ? true : + (role == "local" && (!this._isServer && !this._isClient)) ? true : + (role == "local" && (this._isClient && this._isTerminable)) ? true : + (role == "local") ? false : + (role == "proxy" && this._isClient && this._isServer) ? true : + (role == "proxy") ? false : + (role == "client") ? this._isClient : + (role == "server") ? this._isServer : false; return response; }; @@ -306,10 +306,10 @@ vantage.use = function(commands, options) { */ vantage._getHistory = function(direction) { - if (direction == 'up') { + if (direction == "up") { this._histCtr++; this._histCtr = (this._histCtr > this._hist.length) ? this._hist.length : this._histCtr; - } else if (direction == 'down') { + } else if (direction == "down") { this._histCtr--; this._histCtr = (this._histCtr < 1) ? 1 : this._histCtr; } @@ -318,7 +318,7 @@ vantage._getHistory = function(direction) { /** * Handles tab-completion. Takes a partial - * string as 'he' and fills it in to 'help', etc. + * string as "he" and fills it in to "help", etc. * Works the same as a linux terminal's auto-complete. * * @param {String} str @@ -355,7 +355,7 @@ vantage._autocomplete = function(str, arr) { } } if (matches.length == 1) { - return matches[0] + ' '; + return matches[0] + " "; } else if (matches.length == 0) { return void 0; } else { @@ -497,12 +497,12 @@ vantage.command = function(name, desc, opts) { name = String(name); var args = - (name.indexOf('[') > -1) ? name.split('[') : - (name.indexOf('<') > -1) ? name.split('<') : [name]; + (name.indexOf("[") > -1) ? name.split("[") : + (name.indexOf("<") > -1) ? name.split("<") : [name]; if (args[1]) { - args[1] = (String(args[1]).indexOf(']') > -1) ? '[' + args[1] : args[1]; - args[1] = (String(args[1]).indexOf('>') > -1) ? '<' + args[1] : args[1]; + args[1] = (String(args[1]).indexOf("]") > -1) ? "[" + args[1] : args[1]; + args[1] = (String(args[1]).indexOf(">") > -1) ? "<" + args[1] : args[1]; } var cmd = new Command(String(args.shift()).trim(), exports); @@ -625,12 +625,12 @@ vantage.prompt = function(options, cb) { }); } else { - self.on('vantage-prompt-upstream', function(data){ + self.on("vantage-prompt-upstream", function(data){ var response = data.value; cb(response); }); - self._send('vantage-prompt-downstream', 'downstream', { options: options, value: void 0 }); + self._send("vantage-prompt-downstream", "downstream", { options: options, value: void 0 }); } return self; }; @@ -641,7 +641,7 @@ vantage._refresh = function() { this._activePrompt.clean(); this._midPrompt = false; this._cancelled = true; - if (this._activePrompt.status != 'answered') { + if (this._activePrompt.status != "answered") { this._activePrompt.status = "answered"; this._activePrompt.done(); } @@ -662,7 +662,7 @@ vantage._pause = function() { }, vantage._resume = function(val) { - val = val || ''; + val = val || ""; if (!this._activePrompt) { return } if (this._midPrompt) { return } this._prompt(); @@ -687,8 +687,8 @@ vantage._prompt = function() { // If we somehow got to _prompt and aren't the // local client, send the command downstream. - if (this.is('server')) { - this._send('vantage-resume-downstream', 'downstream'); + if (this.is("server")) { + this._send("vantage-resume-downstream", "downstream"); return; } @@ -714,9 +714,9 @@ vantage._prompt = function() { var str = String(result.command).trim(); - self.emit('client_prompt_submit', str); + self.emit("client_prompt_submit", str); - if (str == '') { self._prompt(); return; } + if (str == "") { self._prompt(); return; } self.exec(str, function(){ self._prompt(); @@ -821,14 +821,14 @@ vantage._execQueueItem = function(cmd) { vantage._exec = function(item) { item = item || {} - item.command = item.command || ''; + item.command = item.command || ""; var self = this; - var parts = item.command.split(' '); + var parts = item.command.split(" "); var path = []; var match = false; var args; - // History for our 'up' and 'down' arrows. + // History for our "up" and "down" arrows. this._hist.push(item.command); // Reverse drill-down the string until you find the @@ -880,9 +880,9 @@ vantage._exec = function(item) { // and throws help. for (var i = 0; i < origOptions.length; ++i) { var o = origOptions[i]; - var short = String(o.short || '').replace(/-/g, ''); - var long = String(o.long || '').replace(/--no-/g, '').replace(/-/g, ''); - var flag = String(o.flags).slice(Math.abs(o.required), o.flags.length).replace('>', '').trim(); + var short = String(o.short || "").replace(/-/g, ""); + var long = String(o.long || "").replace(/--no-/g, "").replace(/-/g, ""); + var flag = String(o.flags).slice(Math.abs(o.required), o.flags.length).replace('>', "").trim(); var exists = parsedArgs[short] || parsedArgs[long]; if (exists === undefined && o.required !== 0) { self.log(" "); @@ -939,7 +939,7 @@ vantage._exec = function(item) { return item.resolve(data); } }).catch(function(err) { - self.log(['', ' Error: '.red + err, '']); + self.log(["", ' Error: '.red + err, '']); if (self.is('local')) { self.emit('client_command_error', { command: item.command, error: err }); } @@ -968,7 +968,7 @@ vantage._exec = function(item) { */ vantage._commandHelp = function(command) { - if (!this.commands.length) return ''; + if (!this.commands.length) return ""; var self = this; var matches = []; @@ -978,7 +978,7 @@ vantage._commandHelp = function(command) { for (var i = 0; i < this.commands.length; ++i) { var parts = String(this.commands[i]._name).split(' '); if (parts.length == 1 && parts[0] == command) { singleMatches.push(command) } - var str = ''; + var str = ""; for (var j = 0; j < parts.length; ++j) { str = String(str + ' ' + parts[j]).trim(); if (str == command) { @@ -990,8 +990,8 @@ vantage._commandHelp = function(command) { var invalidString = (command && matches.length == 0 && singleMatches.length == 0) - ? ['', " Invalid Command. Showing Help:", ''].join('\n') - : ''; + ? ["", " Invalid Command. Showing Help:", ""].join('\n') + : ""; var commandMatch = (matches.length > 0) ? true : false; var commandMatchLength = (commandMatch) ? String(command).trim().split(' ').length+1 : 1; @@ -1009,12 +1009,12 @@ vantage._commandHelp = function(command) { return [ cmd._name + (cmd._alias - ? '|' + cmd._alias - : '') + ? "|" + cmd._alias + : "") + (cmd.options.length - ? ' [options]' - : '') - + ' ' + args + ? " [options]" + : "") + + " " + args , cmd.description() ]; }); @@ -1026,27 +1026,27 @@ vantage._commandHelp = function(command) { var counts = {}; var groups = _.uniq(matches.filter(function(cmd) { - return (String(cmd._name).trim().split(' ').length > commandMatchLength); + return (String(cmd._name).trim().split(" ").length > commandMatchLength); }).map(function(cmd){ - return String(cmd._name).split(' ').slice(0, commandMatchLength).join(' '); + return String(cmd._name).split(" ").slice(0, commandMatchLength).join(" "); }).map(function(cmd){ counts[cmd] = counts[cmd] || 0; counts[cmd]++; return cmd; })).map(function(cmd){ - return ' ' + VantageUtil.pad(cmd + ' *', width) + ' ' + counts[cmd] + ' sub-command' + ((counts[cmd] == 1) ? '' : 's') + '.'; + return " " + VantageUtil.pad(cmd + " *", width) + " " + counts[cmd] + " sub-command" + ((counts[cmd] == 1) ? "" : "s") + "."; }); var str = [ - invalidString + '\n Commands:' - , '' + invalidString + "\n Commands:" + , "" , commands.map(function(cmd) { - return VantageUtil.pad(cmd[0], width) + ' ' + cmd[1]; - }).join('\n').replace(/^/gm, ' ') + return VantageUtil.pad(cmd[0], width) + " " + cmd[1]; + }).join("\n").replace(/^/gm, " ") , (groups.length < 1 - ? '' - : '\n Command Groups:\n\n' + groups.join('\n') + '\n') - ].join('\n'); + ? "" + : "\n Command Groups:\n\n" + groups.join("\n") + "\n") + ].join("\n"); return str; }; @@ -1067,15 +1067,15 @@ vantage._commandHelp = function(command) { vantage._send = function(str, direction, data, options) { options = options || {} - if (direction == 'upstream') { + if (direction == "upstream") { this.client.io.emit(str, data); - } else if (direction == 'downstream') { + } else if (direction == "downstream") { if (options.sessionId) { var session = _.findWhere(this.server.sessions, { id: options.sessionId }); if (session) { session.io.emit(str, data); } else { - throw new Error('No Sessions!!!! This should not happen...'); + throw new Error("No Sessions!!!! This should not happen..."); } } else { for (var i = 0; i < this.server.sessions.length; ++i) { @@ -1104,7 +1104,7 @@ vantage._send = function(str, direction, data, options) { vantage._proxy = function(str, direction, data, options) { var self = this; return new Promise(function(resolve, reject){ - if (self.is('proxy')) { + if (self.is("proxy")) { self._send(str, direction, data, options); } else { resolve(); @@ -1124,10 +1124,10 @@ vantage._proxy = function(str, direction, data, options) { vantage._keypressHandler = function(e, prompt) { this._activePrompt = prompt; var key = (e.key || {}).name; - var keyMatch = (['up', 'down', 'tab'].indexOf(key) > -1); + var keyMatch = (["up", "down", "tab"].indexOf(key) > -1); var value = (prompt) ? String(prompt.rl.line).trim() : void 0; - if (this.is('local')) { + if (this.is("local")) { if (keyMatch) { var result = this._getKeypressResult(key, value); if (result !== undefined) { @@ -1137,7 +1137,7 @@ vantage._keypressHandler = function(e, prompt) { this._histCtr = 0; } } else { - this._send('vantage-keypress-upstream', 'upstream', { key: key, value: value }); + this._send("vantage-keypress-upstream", "upstream", { key: key, value: value }); } }; @@ -1151,9 +1151,9 @@ vantage._keypressHandler = function(e, prompt) { */ vantage._getKeypressResult = function(key, value) { - if (['up', 'down'].indexOf(key) > -1) { + if (["up", "down"].indexOf(key) > -1) { return this._getHistory(key); - } else if (key == 'tab') { + } else if (key == "tab") { return str = this._getAutocomplete(value); } }; @@ -1184,7 +1184,7 @@ vantage.listen = function(app, options) { vantage.exit = function(options, cb) { var self = this; - if (this.is('local') && !this.is('terminable')) { + if (this.is("local") && !this.is("terminable")) { if (options.force) { process.exit(1); } else { @@ -1192,7 +1192,7 @@ vantage.exit = function(options, cb) { type: "confirm", name: "continue", default: false, - message: "This will actually kill this node process. Continue?", + message: "This will actually kill this node process. Continue?" }, function(result){ if (result.continue) { process.exit(1); @@ -1202,11 +1202,11 @@ vantage.exit = function(options, cb) { }); } } else { - // to do - don't handle multiple sessions on exit - i'm + // to do - don't handle multiple sessions on exit - i'm // just kicking everyone out. for (var i = 0; i < self.server.sessions.length; ++i) { var ssn = self.server.sessions[i]; - ssn.io.emit('vantage-close-downstream'); + ssn.io.emit("vantage-close-downstream"); } } }; diff --git a/package.json b/package.json old mode 100644 new mode 100755 index f7759f4..aac0603 --- a/package.json +++ b/package.json @@ -57,5 +57,15 @@ "lib", "bin", "examples" - ] + ], + "eslintConfig": { + "env": { + "node": true, + "browser": false + }, + "rules": { + "no-underscore-dangle": 0, + "no-process-exit": 0 + } + } }