From 587117354d2acf101104a5c0fa324acc04e2f799 Mon Sep 17 00:00:00 2001 From: dev2a Date: Sat, 29 Dec 2018 20:21:38 +0100 Subject: [PATCH] [Fix] inconsistent return --- .eslintrc | 2 +- Commands/init.js | 3 ++- Commands/laravelConfig.js | 3 ++- Commands/missingJob.js | 6 ++++-- Commands/modelsCreator.js | 3 ++- lib/Config.js | 3 +-- lib/Mail.js | 9 ++++++--- lib/db-models/lib/Model-export.js | 11 +++++++---- lib/shell/lib/Shell.js | 3 +-- lib/shell/lib/plugins/help.js | 12 ++++++++---- lib/shell/lib/plugins/router.js | 8 ++++---- lib/shell/lib/routes/shellOnly.js | 2 +- lib/utils.js | 1 + 13 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.eslintrc b/.eslintrc index 58664ac..5a704c4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,7 +37,7 @@ "accessor-pairs": 2, "block-scoped-var": 2, "complexity": [2, 15], - "consistent-return": 0, + "consistent-return": 2, "curly": 2, "default-case": 1, "dot-location": 0, diff --git a/Commands/init.js b/Commands/init.js index 1bdc26f..259a9e9 100644 --- a/Commands/init.js +++ b/Commands/init.js @@ -25,7 +25,8 @@ var checkArtisan = function checkArtisan(cmdRes) { return new Promise(function promiseCheckArtisan(resolve, reject) { var test = cmdRes.match(/\s*Laravel\s+Framework\s+(version)?\s+(.*)/); if (test) { - return resolve(test); + resolve(test); + return; } reject(new Error('not a laravel framework')); }); diff --git a/Commands/laravelConfig.js b/Commands/laravelConfig.js index a81ac2d..a2e1bb8 100644 --- a/Commands/laravelConfig.js +++ b/Commands/laravelConfig.js @@ -20,7 +20,8 @@ var prepareTmpFolder = function prepareTmpFolder() { unsafeCleanup: true }, function tmpDirCallback(err, name) { if (err) { - return reject(err); + reject(err); + return; } fs.mkdir(name + '/Config-laravel') .then(function tmpdirOk() { diff --git a/Commands/missingJob.js b/Commands/missingJob.js index fca0883..6da6c36 100644 --- a/Commands/missingJob.js +++ b/Commands/missingJob.js @@ -92,11 +92,13 @@ module.exports = { if (!app.config('app')) { res.red('app config missing').ln(); res.yellow('see manual for setup config from laravel').ln(); - return res.prompt(); + res.prompt(); + return; } if (Object.keys(app.config('app.job', [])).length === 0) { res.yellow('no job in Config/app.js').ln(); - return res.prompt(); + res.prompt(); + return; } global.queueOption = {}; Job = includeAll({ diff --git a/Commands/modelsCreator.js b/Commands/modelsCreator.js index b2d28d7..886e02e 100644 --- a/Commands/modelsCreator.js +++ b/Commands/modelsCreator.js @@ -9,7 +9,8 @@ module.exports = { function: function run(req, res) { if (app.config('core.modelsCreator.models').length === 0) { res.yellow('Please add models to import in Config/core.js').ln(); - return res.prompt(); + res.prompt(); + return; } var dbModels = require('../lib/db-models'); dbModels() diff --git a/lib/Config.js b/lib/Config.js index e59057d..0ad5ad2 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -1,5 +1,4 @@ 'use strict'; -/* global app */ var include = require('include-all'); var fs = require('fs'); @@ -30,7 +29,7 @@ var Config = function Config(appdir, logger) { Config.prototype.get = function get(key, def) { var reduce = function reduce(obj, index) { if (!obj) { - return; + return null; } return obj[index]; }; diff --git a/lib/Mail.js b/lib/Mail.js index e680c80..6e6211b 100644 --- a/lib/Mail.js +++ b/lib/Mail.js @@ -71,12 +71,15 @@ Mail.prototype.send = function sendMail(callback) { self.mailer.sendMail(mailOptions, function mailerSendMail(err, info) { if (err) { if (callback) { - return callback(err); + callback(err); + return; } - return reject(err); + reject(err); + return; } if (callback) { - return callback(null, info); + callback(null, info); + return; } resolve(info); }); diff --git a/lib/db-models/lib/Model-export.js b/lib/db-models/lib/Model-export.js index 982c4f8..72340dc 100644 --- a/lib/db-models/lib/Model-export.js +++ b/lib/db-models/lib/Model-export.js @@ -29,13 +29,16 @@ ModelExport.prototype.createOutputDir = function createOutputDir() { return new Promise(function PromiseCreateOutputDir(resolve) { fs.stat(self.dir, function statDir(err, stats) { if (err || !stats.isDirectory()) { - return fs.mkdir(self.dir, function mkdir(mkdirErr) { + fs.mkdir(self.dir, function mkdir(mkdirErr) { if (!mkdirErr) { - return resolve(true); + resolve(true); + return; } }); + return; } - return resolve(true); + resolve(true); + return; }); }); }; @@ -105,7 +108,7 @@ ModelExport.prototype.createModels = function createModels() { } //for future association self.associate[lowerName] = modelName; - return generatePromises.push(self.generateTemps({ + generatePromises.push(self.generateTemps({ tableName: table, modelName: modelName, fields: results[1][table] diff --git a/lib/shell/lib/Shell.js b/lib/shell/lib/Shell.js index 9081c90..2e347d8 100644 --- a/lib/shell/lib/Shell.js +++ b/lib/shell/lib/Shell.js @@ -1,5 +1,4 @@ 'use strict'; -/* global app */ /*eslint no-magic-numbers: 0 */ var EventEmitter, Interface, Request, Response, shell, events, readline; @@ -219,7 +218,7 @@ shell = (function exportShell(_super) { } else if (this.parent) { return this.parent.set(setting); } - + return this; }; Shell.prototype.prompt = function prompt() { diff --git a/lib/shell/lib/plugins/help.js b/lib/shell/lib/plugins/help.js index 3464448..be1e98d 100644 --- a/lib/shell/lib/plugins/help.js +++ b/lib/shell/lib/plugins/help.js @@ -50,7 +50,8 @@ module.exports = function help(settings) { var route = routes[shell.routeName[command]]; if (!route) { res.red('command ' + command + ' not found'); - return res.prompt(); + res.prompt(); + return; } res.yellow('Help:').ln(); res.print(pad('', firstPad)).white(route.description).ln().ln(); @@ -90,7 +91,8 @@ module.exports = function help(settings) { res.ln(); }); - return res.prompt(); + res.prompt(); + return; } var routeText; res.yellow('Available commands:'); @@ -102,14 +104,16 @@ module.exports = function help(settings) { res.print(pad('', firstPad)).green(routeText).white(rte.description).ln(); } }); - return res.prompt(); + res.prompt(); + return; }; console.log('add routes'); shell.cmd('help {command(([\\w\\:])*)?}', 'Show this message', shell.help.bind(shell)); shell.cmd('', shell.help.bind(shell)); if (shell.isShell && settings.introduction) { text = typeof settings.introduction === 'string' ? settings.introduction : introduction; - return shell.styles.println(text); + shell.styles.println(text); + return; } }; diff --git a/lib/shell/lib/plugins/router.js b/lib/shell/lib/plugins/router.js index 218cca0..06542d0 100644 --- a/lib/shell/lib/plugins/router.js +++ b/lib/shell/lib/plugins/router.js @@ -59,10 +59,10 @@ var match = function match(req, routes) { if ((/^\-\-/).test(arg)) { arg = arg.replace('--', ''); route.options[arg] = true; - return; + return ; } if (keyArg >= keys.length) { - return; + return ; } param = keys.shift(); key = param.key; @@ -83,7 +83,7 @@ var match = function match(req, routes) { req._route_index = routeKey; // throw new Error('missing parameter'); routeOk = route; - return false; + return; } }); // console.debug('routes:',routes); @@ -121,7 +121,7 @@ module.exports = function router(settings) { var args, route; args = Array.prototype.slice.call(arguments); if (!args[0]) { - return; + return this; } route = {}; route.command = args.shift(); diff --git a/lib/shell/lib/routes/shellOnly.js b/lib/shell/lib/routes/shellOnly.js index 04c9701..e1501bd 100644 --- a/lib/shell/lib/routes/shellOnly.js +++ b/lib/shell/lib/routes/shellOnly.js @@ -13,5 +13,5 @@ module.exports = function shellOnly(req, res, next) { res.prompt(); return; } - return next(); + next(); }; diff --git a/lib/utils.js b/lib/utils.js index b32a37a..29151c4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -41,6 +41,7 @@ module.exports = { return path.normalize(dir + '/..'); } } + throw new Error('Workspace not found'); } };