Skip to content
← Back to rules

oxc/missing-throw 正确性

This rule is turned on by default.
💡 A suggestion is available for this rule.

作用

检查 throw 关键字是否缺失在 new 表达式前面。

为什么这不好?

new 表达式前面需要 throw 关键字才能抛出错误。省略它通常是一个错误。

示例

此规则的错误代码示例:

javascript
function foo() {
  throw Error();
}
const foo = () => {
  new Error();
};

此规则的正确代码示例:

javascript
function foo() {
  throw new Error();
}
const foo = () => {
  throw new Error();
};

如何使用

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

json
{
  "rules": {
    "oxc/missing-throw": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/missing-throw": "error",
  },
});
bash
oxlint --deny oxc/missing-throw

版本

此规则于 v0.0.3 中添加。

参考