noFallthroughSwitchClause
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noFallthroughSwitchClause¥Diagnostic Category:
lint/suspicious/noFallthroughSwitchClause -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-fallthrough相同¥Same as
no-fallthrough
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noFallthroughSwitchClause": "error" } } }}¥Description
禁止 switch 子句的 fallthrough。
¥Disallow fallthrough of switch clauses.
switch 语句中的 Switch 子句默认失败。如果忘记,这可能会导致意外行为。
¥Switch clauses in switch statements fall through by default.
This can lead to unexpected behavior when forgotten.
该规则不考虑
process.exit()。¥The rule doesn’t take
process.exit()in consideration.
¥Examples
¥Invalid
switch (bar) { case 0: a(); case 1: b();}code-block.js:2:2 lint/suspicious/noFallthroughSwitchClause ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This case is falling through to the next case.
1 │ switch (bar) {
> 2 │ case 0:
│ ^^^^^^^
> 3 │ a();
│ ^^^^
4 │ case 1:
5 │ b();
ℹ Add a `break` or `return` statement to the end of this case to prevent fallthrough.
¥Valid
switch (foo) { case 1: case 2: doSomething(); break; case 3: { if (cond) { break; } else { break; } } case 4: doSomething();}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号