Skip to content

Commit

Permalink
ci: tweak ESLint config, small refactors (#422)
Browse files Browse the repository at this point in the history
* ci: update eslint config to warn about console.log calls

also adding an explanatory comment

* refactor: disable ESLint, slight refactors to make it more readable
  • Loading branch information
kanadgupta authored Jan 8, 2022
1 parent 3d03bb8 commit f842480
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }]
}
}
25 changes: 10 additions & 15 deletions bin/rdme
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'[email protected]'
)}.`;

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(
'[email protected]'
)}.\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);
});

0 comments on commit f842480

Please sign in to comment.