Async Without Await

Declaration should not be async if it doesn’t use await

  • Identifier: async_without_await
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

func test() {
    func test() async {
        await test()
    }
},
func test() {
    func test() async {
        await test().value
    }
},
func test() async {
    await scheduler.task { foo { bar() } }
}
func test() async {
    perform(await try foo().value)
}
func test() async {
    perform(try await foo())
}
func test() async {
    await perform()
    func baz() {
        qux()
    }
}
let x: () async -> Void = {
    await test()
}
let x: () async -> Void = {
    await { await test() }()
}
func test() async {
    await foo()
}
let x = { bar() }
let x: (() async -> Void)? = {
    await { await test() }()
}
let x: (() async -> Void)? = nil
let x: () -> Void = { test() }
var test: Int {
    get async throws {
        try await foo()
    }
}
var foo: Int {
    get throws {
        try bar()
    }
}
init() async {
    await foo()
}
init() async {
    func test() async {
        await foo()
    }
    await { await foo() }()
}
subscript(row: Int) -> Double {
    get async {
        await foo()
    }
}
func foo() async -> Int
func bar() async -> Int
var foo: Int { get async }
var bar: Int { get async }
init(foo: bar) async
init(baz: qux) async
let baz = { qux() }
typealias Foo = () async -> Void
typealias Bar = () async -> Void
let baz = { qux() }
func test() async {
    for await foo in bar {}
}
func test() async {
    while let foo = await bar() {}
}
func test() async {
    async let foo = bar()
    let baz = await foo
}
func test() async {
    async let foo = bar()
    await foo
}
func test() async {
    async let foo = bar()
}
func foo(bar: () async -> Void) { { } }
func foo(bar: () async -> Void = { await baz() }) { {} }
func foo() -> (() async -> Void)? { {} }
func foo(
    bar: () async -> Void,
    baz: () -> Void = {}
) { { } }
func foo(bar: () async -> Void = {}) { }

Triggering Examples

func test() async {
    perform()
}
func test() {
    func baz() async {
        qux()
    }
    perform()
    func baz() {
        qux()
    }
}
func test() async {
    func baz() async {
        await qux()
    }
}
func test() async {
  func foo() async {}
  let bar = { await foo() }
}
func test() async {
    let bar = {
        func foo() async {}
    }
}
let x: (() async -> Void)? = { test() }
var test: Int {
    get async throws {
        foo()
    }
}
var test: Int {
    get async throws {
        func foo() async {}
        let bar = { await foo() }
    }
}
var test: Int {
    get throws {
        func foo() {}
        let bar: () async -> Void = { foo() }
    }
}
init() async {}
init() async {
    func foo() async {}
    let bar: () async -> Void = { foo() }
}
subscript(row: Int) -> Double {
    get async {
        1.0
    }
}
func test() async {
    for foo in bar {}
}
func test() async {
    while let foo = bar() {}
}