Pattern: Inert defer
Issue: -
If defer is at the end of its parent scope, it will be executed right where it is anyway.
Examples of correct code:
func example3() {
defer { /* deferred code */ }
print("other code")
}
func example4() {
if condition {
defer { /* deferred code */ }
print("other code")
}
}
Examples of incorrect code:
func example0() {
↓defer { /* deferred code */ }
}
func example1() {
↓defer { /* deferred code */ }
// comment
}
func example2() {
if condition {
↓defer { /* deferred code */ }
// comment
}
}