No Empty Block

Code blocks should contain at least one statement or comment

  • Identifier: no_empty_block
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    disabled_block_types []

Non Triggering Examples

func f() {
    /* do something */
}

var flag = true {
    willSet { /* do something */ }
}
class Apple {
    init() { /* do something */ }

    deinit { /* do something */ }
}
for _ in 0..<10 { /* do something */ }

do {
    /* do something */
} catch {
    /* do something */
}

func f() {
    defer {
        /* do something */
    }
    print("other code")
}

if flag {
    /* do something */
} else {
    /* do something */
}

repeat { /* do something */ } while (flag)

while i < 10 { /* do something */ }
//
// disabled_block_types: [function_bodies]
//

func f() {}

var flag = true {
    willSet {}
}

//
// disabled_block_types: [initializer_bodies]
//

class Apple {
    init() {}

    deinit {}
}

//
// disabled_block_types: [statement_blocks]
//

for _ in 0..<10 {}

do {
} catch {
}

func f() {
    defer {}
    print("other code")
}

if flag {
} else {
}

repeat {} while (flag)

while i < 10 {}

f { _ in /* comment */ }
f { _ in // comment
}
f { _ in
    // comment
}
//
// disabled_block_types: [closure_blocks]
//

f {}
{}()

Triggering Examples

func f() {}

var flag = true {
    willSet {}
}
class Apple {
    init() {}

    deinit {}
}
for _ in 0..<10 {}

do {
} catch {
}

func f() {
    defer {}
    print("other code")
}

if flag {
} else {
}

repeat {} while (flag)

while i < 10 {}
f {}
Button {} label: {}