no-empty
NOTE: this rule is part of the
推荐
rule set.Enable full set in
deno.json
:{ "lint": { "rules": { "tags": ["推荐"] } } }
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include
or exclude
array in deno.json
:{ "lint": { "rules": { "include": ["no-empty"], "exclude": ["no-empty"] } } }
禁止使用空的块语句。
空的块语句是合法的,但通常表示某些内容被遗漏,从而可能降低代码的可读性。此规则忽略仅包含注释的块语句。此规则也忽略空的构造函数和函数体(包括箭头函数)。
无效:
if (foo) {}
while (foo) {}
switch (foo) {}
try {
doSomething();
} catch (e) {
} finally {
}
有效:
if (foo) {
// 空
}
while (foo) {
/* 空 */
}
try {
doSomething();
} catch (e) {
// 无论错误如何,继续
}
try {
doSomething();
} finally {
/* 无论错误如何,继续 */
}