Skip to content
← Back to rules

unicorn/prefer-optional-catch-binding Style

🛠️ An auto-fix is available for this rule.

作用

如果 catch 绑定参数未被使用,则应省略它。

为什么这不好?

如果错误未被使用,那么将其绑定到一个变量上是没有必要的。

示例

此规则的不正确代码示例:

javascript
try {
  // ...
} catch (e) {}

此规则的正确代码示例:

javascript
try {
  // ...
} catch {}

如何使用

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

json
{
  "rules": {
    "unicorn/prefer-optional-catch-binding": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/prefer-optional-catch-binding": "error",
  },
});
bash
oxlint --deny unicorn/prefer-optional-catch-binding

版本

此规则于 v0.0.17 中添加。

参考资料