-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
discussionTopics that cannot be categorized as bugs or enhancements yet. They require further discussions.Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.rule-requestRequests for a new rules.Requests for a new rules.
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
Disallow async
functions which have no await
expression.
- Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
async
functions that don't suspend contradict the Swift Concurrency documentation which specifies they are able to suspend partway through execution.
Asynchronous functions that don’t use await can cause confusion in that a programmer awaiting such a function may assume it's guaranteed to execute its work in the background. Although such an assumption is a fundamental misunderstanding of Swift Concurrency, there are plenty of examples.
Async functions without await are a common and unintentional result of refactoring.
- Provide several examples of what would and wouldn't trigger violations.
Pass:
func f() async {
await fetch();
}
Fail:
func add(a: Int, b: Int) async {
return a + b
}
-
Should the rule be configurable, if so what parameters should be configurable?
There may be edge cases where async without await is appropriate that I'm not thinking of. -
Should the rule be opt-in or enabled by default? Why?
Enabled by default
I believe this rule would be fast, is not prone to false positives and is general consensus.
Metadata
Metadata
Assignees
Labels
discussionTopics that cannot be categorized as bugs or enhancements yet. They require further discussions.Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.rule-requestRequests for a new rules.Requests for a new rules.