useDefaultSwitchClause
¥Summary
-
规则生效日期:
v1.7.2¥Rule available since:
v1.7.2 -
诊断类别:
lint/style/useDefaultSwitchClause¥Diagnostic Category:
lint/style/useDefaultSwitchClause -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
default-case相同¥Same as
default-case
-
¥How to configure
{ "linter": { "rules": { "style": { "useDefaultSwitchClause": "error" } } }}¥Description
要求 switch 语句中有 default 子句。
¥Require the default clause in switch statements.
某些代码约定要求所有 switch 语句都有一个默认子句。想法是,最好始终明确说明默认行为应该是什么,以便清楚开发者是否忘记错误地包含默认行为。
¥Some code conventions require that all switch statements have a default clause. The thinking is that it’s better to always explicitly state what the default behavior should be so that it’s clear whether or not the developer forgot to include the default behavior by mistake.
¥Examples
¥Invalid
switch (a) { case 1: /* code */ break;}code-block.js:1:1 lint/style/useDefaultSwitchClause ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Expected a default switch clause.
> 1 │ switch (a) {
│ ^^^^^^^^^^^^
> 2 │ case 1:
> 3 │ /* code */
> 4 │ break;
> 5 │ }
│ ^
6 │
ℹ The lack of a default clause can be a possible omission.
ℹ Consider adding a default clause.
¥Valid
switch (a) { case 1: /* code */ break; default: /* code */ break;}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号