Skip to content
← Back to rules

eslint/no-empty Restriction

💡 A suggestion is available for this rule.

它的作用

禁止空的代码块语句。

为什么这不好?

空的代码块语句虽然从技术上说不算错误,但通常是由于重构未完成而出现的。 它们会让代码阅读时产生困惑。

示例

以下是此规则的错误代码示例:

javascript
if (condition) {
}

以下是此规则的正确代码示例:

javascript
if (condition) {
  throw new Error("condition should be false");
}

配置

此规则接受一个包含以下属性的配置对象:

allowEmptyCatch

type: boolean

default: false

如果设置为 true,则允许空的 catch 块,而不会触发 linter。

如何使用

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

json
{
  "rules": {
    "no-empty": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-empty": "error",
  },
});
bash
oxlint --deny no-empty

版本

此规则于 v0.0.3 中添加。

参考资料