Understand the n/process-exit-as-throw rule
masterThe n/process-exit-as-throw rule ensures that code following a process.exit() call is correctly identified as unreachable by ESLint.
By default, ESLint does not treat process.exit() as a terminating expression (unlike throw or return). This can cause other rules, such as consistent-return, to trigger false positive warnings on code that follows a process.exit() call because ESLint assumes the code path continues.
This rule overrides the default code path analyzer to mark code after process.exit() as unreachable, preventing these false positives. Note that this rule itself does not issue warnings; it facilitates the correct behavior of other ESLint rules.
function foo(a) {
if (a) {
return new Bar();
} else {
process.exit(1);
}
// Without this rule, ESLint might think code here is reachable,
// potentially triggering warnings from rules like 'consistent-return'.
}