Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't place code after a process-terminating call
Statements after process.exit() (or any process-terminating call) are unreachable dead code and should be removed.
Bad example
| 1 | function shutdown(code: number): number { |
| 2 | cleanup(); |
| 3 | process.exit(code); |
| 4 | return code; // unreachable: process.exit never returns |
| 5 | } |
Explanation (EN)
process.exit() terminates the process immediately and never returns, so the return statement after it can never run. It is dead code that misleads readers into thinking a value is produced.
Objašnjenje (HR)
process.exit() trenutno zaustavlja proces i nikada se ne vraca, pa se return iza njega nikada ne moze izvrsiti. To je mrtav kod koji navodi citatelja na krivi zakljucak da funkcija vraca vrijednost.
Good example
| 1 | function shutdown(code: number): never { |
| 2 | cleanup(); |
| 3 | process.exit(code); |
| 4 | } |
Explanation (EN)
Let process.exit() be the final statement and type the function as `never` to signal it does not return. No unreachable code remains, and the intent is explicit.
Objašnjenje (HR)
Neka process.exit() bude zadnja naredba, a funkciju tipiziraj kao `never` da naznacis da se ne vraca. Nema vise nedohvatljivog koda, a namjera je eksplicitna.
Notes (EN)
The same applies after throw, an infinite loop, or any call typed as `never`. Linters like no-unreachable / eslint catch most cases.
Bilješke (HR)
Isto vrijedi i iza throw-a, beskonacne petlje ili bilo kojeg poziva tipiziranog kao `never`. Linteri poput no-unreachable / eslint hvataju vecinu slucajeva.