unnecessary_breaks
Don't use explicit break
s when a break is implied.
此规则自 Dart 3.0 版本起可用。
此规则提供 快速修复 。
详情
#Only use a break
in a non-empty switch case statement if you need to break before the end of the case body. Dart does not support fallthrough execution for non-empty cases, so break
s at the end of non-empty switch case statements are unnecessary.
BAD:
switch (1) {
case 1:
print("one");
break;
case 2:
print("two");
break;
}
GOOD:
switch (1) {
case 1:
print("one");
case 2:
print("two");
}
switch (1) {
case 1:
case 2:
print("one or two");
}
switch (1) {
case 1:
break;
case 2:
print("just two");
}
NOTE: This lint only reports unnecessary breaks in libraries with a language version of 3.0 or greater. Explicit breaks are still required in Dart 2.19 and below.
使用方法
#要启用 unnecessary_breaks
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 unnecessary_breaks
:
linter:
rules:
- unnecessary_breaks
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.