Skip to content
← Back to rules

unicorn/no-process-exit Restriction

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does ​

Disallow all usage of process.exit().

Why is this bad? ​

process.exit() should generally only be used in command-line utilities. In all other types of applications, the code should throw an error instead.

Examples ​

Examples of incorrect code for this rule:

javascript
if (problem) {
  process.exit(1);
}

Examples of correct code for this rule:

javascript
if (problem) {
  throw new Error("message");
}
#!/usr/bin/env node
if (problem) {
  process.exit(1);
}

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-process-exit": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-process-exit": "error",
  },
});
bash
oxlint --deny unicorn/no-process-exit

Version ​

This rule was added in v0.2.9.

References ​