control_flow_in_finally
finally ブロック内での制御フローは避けてください。
詳細
#finally ブロックからの制御フローを避ける。
finally ブロックで制御フローを使用すると、デバッグが困難な予期しない動作が必然的に発生します。
悪い例
dart
class BadReturn {
double nonCompliantMethod() {
try {
return 1 / 0;
} catch (e) {
print(e);
} finally {
return 1.0; // LINT
}
}
}悪い例
dart
class BadContinue {
double nonCompliantMethod() {
for (var o in [1, 2]) {
try {
print(o / 0);
} catch (e) {
print(e);
} finally {
continue; // LINT
}
}
return 1.0;
}
}悪い例
dart
class BadBreak {
double nonCompliantMethod() {
for (var o in [1, 2]) {
try {
print(o / 0);
} catch (e) {
print(e);
} finally {
break; // LINT
}
}
return 1.0;
}
}良い例
dart
class Ok {
double compliantMethod() {
var i = 5;
try {
i = 1 / 0;
} catch (e) {
print(e); // OK
}
return i;
}
}有効にする
#control_flow_in_finally ルールを有効にするには、analysis_options.yaml ファイルの linter > rules の下に control_flow_in_finally を追加してください。
analysis_options.yaml
yaml
linter:
rules:
- control_flow_in_finally代わりに YAML マップ構文を使用してリンタルールを設定している場合は、linter > rules の下に control_flow_in_finally: true を追加してください。
analysis_options.yaml
yaml
linter:
rules:
control_flow_in_finally: true