-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
Rule proposal: Prefer setting process.exitCode
to calling process.exit()
#1530
Comments
exitcode
exitcode
to calling process.exit
exitcode
to calling process.exit
process.exitCode
to calling process.exit()
One problem with this is that you cannot use if (cli.input.length === 0) {
console.log('Please specify a unicorn');
process.exit(1);
}
init(); If we use |
This comment was marked as resolved.
This comment was marked as resolved.
Wouldn't it be "better" to just throw? I know it's ugly, but at least it's guaranteed. The note in docs still applies:
That code can use |
Alternatively: (() => {
if (cli.input.length === 0) {
console.log('Please specify a unicorn');
process.exitCode = 1;
return;
}
// ...
})();
// or
if (cli.input.length === 0) {
console.log('Please specify a unicorn');
process.exitCode = 1;
} else {
// ...
} So annoying that we cannot use |
Sidenote, maybe |
To be honest I'd rather just always wrap my logic in an init function in any case, even if that "prefer top level await" rule warns against it. I very rarely have any logic at the top level anyway, unless trivial. So in this case I'd use function init() {
}
init(); instead of the IIFE, so it looks decent and pretty standard. |
The IIFE was not the point of my comment though. I could have used a "main" function there too. |
Extends:
no-process-exit
rule #1prefer-queue-microtask
#1346Context:
I'm not sure if this is applicable to every situation, but perhaps
process.exit(1)
should be the exception, not the rule.Fail
Pass
The text was updated successfully, but these errors were encountered: