unicorn/no-process-exit Restriction
它的作用
禁止对 process.exit() 的所有使用。
为什么这不好?
process.exit() 通常只应在命令行工具中使用。在所有其他 类型的应用程序中,代码应该改为抛出错误。
示例
以下是此规则的错误代码示例:
javascript
if (problem) {
process.exit(1);
}以下是此规则的正确代码示例:
javascript
if (problem) {
throw new Error("message");
}#!/usr/bin/env node
if (problem) {
process.exit(1);
}如何使用
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版本
此规则于 v0.2.9 中添加。
