noctcore-code-quality/no-process-exit
noctcore-code-quality/no-process-exit
- Package
- code-quality v1.0.0
- Preset
- recommended
- Severity
- error
- Autofix
- No
- Suggestions
- No
- Options
- Optional
- Type info
- Not needed
process.exit() belongs to bootstrap/shutdown and CLIs — not application code.
process.exit() kills the whole process immediately, skipping pending I/O, finally blocks, and
graceful-shutdown handlers. In request-scoped, service, or renderer code that is a footgun: a single
call can take the entire process down mid-flight. Those layers should throw or reject and let the
lifecycle decide how to tear down. The legitimate exit sites are standalone scripts, CLI entrypoints,
and config files.
What it flags
Section titled “What it flags”Any process.exit(...) call in a file not covered by allowIn. Both the dot form
(process.exit()) and the computed form (process['exit']()) are caught so a computed callee
cannot bypass the rule.
if (!order) { process.exit(1);}if (!order) { throw new Error('order not found');}Moving the exit to a CLI entrypoint is the other fix:
main().catch(() => process.exit(1));What it does not flag
Section titled “What it does not flag”- Files covered by
allowIn: by default scripts,binandclidirectories, and config files. - An
exitmethod on anything other thanprocess(queue.exit(0)). - Setting
process.exitCode, which lets the process finish its work before it ends.
Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
allowIn |
string[] (globs) |
see below | File-path globs where process.exit() is allowed. |
The globs are matched against the file’s absolute path and its path relative to the working directory and to the workspace root (the nearest ancestor holding a lockfile, pnpm-workspace.yaml or .git), so a
repo-relative glob such as apps/server/** works like a flat-config files glob, and a leading **/
(which may match zero leading directories) works from anywhere. Default:
["**/scripts/**", "**/bin/**", "**/cli/**", "**/*.config.{ts,js,mjs,cjs,cts,mts}"]'noctcore-code-quality/no-process-exit': ['error', { allowIn: ['**/scripts/**', '**/*.cli.ts'] }]When not to use it
Section titled “When not to use it”Standalone CLI projects where every file is legitimately an entrypoint.