Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Calling process.exit() in a library or non-CLI module terminates the entire Node.js process, which is almost never the right thing to do. Callers have no opportunity to clean up or handle the exit gracefully. Throwing an error instead gives the caller full control.
Recommendedrecommended · ☑️ unopinionated
Fixable
Suggestions

Examples

// In a regular module — should throw instead
process.exit(0);
Additional patterns that are always allowed:
// Allowed: inside a process event handler
process.on('SIGINT', () => {
  console.log('Got SIGINT');
  process.exit(1);
});

// Allowed: file imports worker_threads
import workerThreads from 'node:worker_threads';

try {
  // do work…
  process.exit(0);
} catch (_) {
  process.exit(1);
}

Allowed contexts

The rule allows process.exit() in three situations:
  1. CLI files — the first line of the file is a hashbang (#!/usr/bin/env node).
  2. Process event handlers — inside a process.on(…) or process.once(…) callback.
  3. Worker thread files — the file imports worker_threads or node:worker_threads.
This is an extension of ESLint’s built-in no-process-exit rule with the three exceptions above added on top.

Build docs developers (and LLMs) love