avoid_empty_else
Empty statements are not allowed in an 'else' clause.
Description
#The analyzer produces this diagnostic when the statement after an else
is an empty statement (a semicolon).
For more information, see the documentation for
avoid_empty_else
.
Example
#The following code produces this diagnostic because the statement
following the else
is an empty statement:
dart
void f(int x, int y) {
if (x > y)
print("1");
else ;
print("2");
}
Common fixes
#If the statement after the empty statement is intended to be executed only
when the condition is false
, then remove the empty statement:
dart
void f(int x, int y) {
if (x > y)
print("1");
else
print("2");
}
If there is no code that is intended to be executed only when the
condition is false
, then remove the whole else
clause:
dart
void f(int x, int y) {
if (x > y)
print("1");
print("2");
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。