Description
Since passing non-integer values to process.exit(code) and process.exitCode is deprecated (DEP0164) and has reached End-of-Life status in Node.js v20.0.0, we should provide a codemod to replace them.
- The codemod should convert non-integer values passed to
process.exit() to proper integers or remove them.
- The codemod should convert non-integer values assigned to
process.exitCode to proper integers or undefined.
- The codemod should preserve
undefined, null, integer numbers, and integer strings (e.g., '1').
- The codemod should add explicit integer conversion for floating-point numbers or other numeric values.
Additional Information
Note that in Node.js v20.0.0, passing values other than undefined, null, integer numbers, and integer strings to process.exit() or assigning them to process.exitCode now throws an ERR_INVALID_ARG_TYPE error.
Exit codes should always be integers between 0-255, where 0 indicates success and non-zero indicates an error. The automatic coercion of non-integer values was removed because it could lead to unexpected behavior.
Examples
Example 1: Boolean value in process.exit()
Before:
After:
process.exit(1); // true coerced to 1
Example 2: Boolean false in process.exit()
Before:
After:
process.exit(0); // false coerced to 0
Example 3: Floating-point number in process.exit()
Before:
After:
process.exit(Math.floor(1.5)); // Explicitly convert to integer: 1
Example 4: Object assigned to process.exitCode
Before:
process.exitCode = { code: 1 };
After:
process.exitCode = 1; // Extract the integer value
Example 5: String (non-integer) in process.exit()
Before:
After:
process.exit(1); // Use appropriate error code
Example 6: Conditional with boolean
Before:
const hasError = true;
process.exit(hasError);
After:
const hasError = true;
process.exit(hasError ? 1 : 0);
Example 7: process.exitCode with boolean
Before:
const success = false;
process.exitCode = success;
After:
const success = false;
process.exitCode = success ? 0 : 1;
Example 8: Valid integer string (no change needed)
Before:
After:
process.exit("1"); // Integer strings are still valid
Example 9: Valid values (no change needed)
Before:
process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;
After:
process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;
Example 10: Arithmetic expression
Before:
process.exit(0.5 + 0.7); // Results in 1.2
After:
process.exit(Math.floor(0.5 + 0.7)); // Explicitly convert to integer: 1
Refs
Description
Since passing non-integer values to
process.exit(code)andprocess.exitCodeis deprecated (DEP0164) and has reached End-of-Life status in Node.js v20.0.0, we should provide a codemod to replace them.process.exit()to proper integers or remove them.process.exitCodeto proper integers orundefined.undefined,null, integer numbers, and integer strings (e.g.,'1').Additional Information
Note that in Node.js v20.0.0, passing values other than
undefined,null, integer numbers, and integer strings toprocess.exit()or assigning them toprocess.exitCodenow throws anERR_INVALID_ARG_TYPEerror.Exit codes should always be integers between 0-255, where 0 indicates success and non-zero indicates an error. The automatic coercion of non-integer values was removed because it could lead to unexpected behavior.
Examples
Example 1: Boolean value in process.exit()
Before:
After:
Example 2: Boolean false in process.exit()
Before:
After:
Example 3: Floating-point number in process.exit()
Before:
After:
Example 4: Object assigned to process.exitCode
Before:
After:
Example 5: String (non-integer) in process.exit()
Before:
After:
Example 6: Conditional with boolean
Before:
After:
Example 7: process.exitCode with boolean
Before:
After:
Example 8: Valid integer string (no change needed)
Before:
After:
Example 9: Valid values (no change needed)
Before:
After:
Example 10: Arithmetic expression
Before:
After:
Refs
process.exit(code),process.exitCodecoercion to integer