noEmptyBlockStatements
¥Summary
-
规则生效日期:
v1.3.0¥Rule available since:
v1.3.0 -
诊断类别:
lint/suspicious/noEmptyBlockStatements¥Diagnostic Category:
lint/suspicious/noEmptyBlockStatements -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
no-empty相同¥Same as
no-empty -
¥Same as
no-empty-static-block -
与
no-empty-function相同¥Same as
no-empty-function -
与
@typescript-eslint/no-empty-function相同¥Same as
@typescript-eslint/no-empty-function
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noEmptyBlockStatements": "error" } } }}¥Description
禁止空块语句和静态块。
¥Disallow empty block statements and static blocks.
空静态块和块语句虽然在技术上不是错误,但通常是由于未完成的重构而发生的。它们可能会在阅读代码时造成混淆。
¥Empty static blocks and block statements, while not technically errors, usually occur due to refactoring that wasn’t completed. They can cause confusion when reading code.
此规则不允许空块语句和静态块。此规则忽略包含注释的块语句或静态块(例如,在 try 语句的空 catch 或 finally 块中,以指示无论是否有错误都应继续执行)。
¥This rule disallows empty block statements and static blocks. This rule ignores block statements or static blocks which contain a comment (for example, in an empty catch or finally block of a try statement to indicate that execution should continue regardless of errors).
¥Examples
¥Invalid
function emptyFunctionBody () {}code-block.js:1:31 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty block.
> 1 │ function emptyFunctionBody () {}
│ ^^
2 │
ℹ Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.
try { doSomething();} catch(ex) {
}code-block.js:3:13 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty block.
1 │ try {
2 │ doSomething();
> 3 │ } catch(ex) {
│ ^
> 4 │
> 5 │ }
│ ^
6 │
ℹ Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.
class Foo { static {}}code-block.js:2:3 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty block.
1 │ class Foo {
> 2 │ static {}
│ ^^^^^^^^^
3 │ }
4 │
ℹ Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.
¥Valid
function foo () { doSomething();}try { doSomething();} catch (ex) { // continue regardless of error}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号