diff --git a/.eslintrc b/.eslintrc index 6067825fd..b1b1c5ff2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,6 +2,16 @@ "extends": ["@readme/eslint-config"], "root": true, "rules": { - "no-console": "off" + /** + * This is a small rule to prevent us from using console.log() statements in our commands. + * + * We've had troubles in the past where our test coverage required us to use Jest mocks for + * console.log() calls, hurting our ability to write resilient tests and easily debug issues. + * + * We should be returning Promise-wrapped values in our main command functions + * so we can write robust tests and take advantage of `bin/rdme`, + * which we use for printing function outputs and returning correct exit codes. + */ + "no-console": ["warn", { "allow": ["info", "warn"] }] } } diff --git a/bin/rdme b/bin/rdme index a4df41dec..57b1f82cb 100755 --- a/bin/rdme +++ b/bin/rdme @@ -3,25 +3,20 @@ const chalk = require('chalk'); require('../src')(process.argv.slice(2)) .then(msg => { + // eslint-disable-next-line no-console if (msg) console.log(msg); - process.exit(0); + return process.exit(0); }) - .catch(e => { - if (e) { - const err = e; + .catch(err => { + let message = `Yikes, something went wrong! Please try again and if the problem persists, get in touch with our support team at ${chalk.underline( + 'support@readme.io' + )}.`; - if ('message' in err) { - console.error(chalk.red(`\n${err.message}\n`)); - } else { - console.error( - chalk.red( - `Yikes, something went wrong! Please try again and if the problem persists, get in touch with our support team at ${chalk.underline( - 'support@readme.io' - )}.\n` - ) - ); - } + if (err && 'message' in err) { + message = err.message; } + // eslint-disable-next-line no-console + console.error(chalk.red(`\n${message}\n`)); return process.exit(1); });