Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: tweak ESLint config, small refactors #422

Merged
merged 2 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
'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);
});