Skip to content

Commit

Permalink
Fix void_return rule to support async and async throws functions (#4772)
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma authored Feb 17, 2023
1 parent 6a9e677 commit 352ffdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#4753](https://github.com/realm/SwiftLint/issues/4753)

* Fix `void_return` rule to support async and async throws functions.
[Mathias Schreck](https://github.com/lo1tuma)
[#4772](https://github.com/realm/SwiftLint/issues/4772)

## 0.50.3: Bundle of Towels

#### Breaking
Expand Down
16 changes: 12 additions & 4 deletions Source/SwiftLintFramework/Rules/Style/VoidReturnRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ struct VoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableRule {
Example("let foo: (ConfigurationTests) -> () throws -> Void\n"),
Example("let foo: (ConfigurationTests) -> () throws -> Void\n"),
Example("let foo: (ConfigurationTests) ->() throws -> Void\n"),
Example("let foo: (ConfigurationTests) -> () -> Void\n")
Example("let foo: (ConfigurationTests) -> () -> Void\n"),
Example("let foo: () -> () async -> Void\n"),
Example("let foo: () -> () async throws -> Void\n"),
Example("let foo: () -> () async -> Void\n"),
Example("func foo() -> () async throws -> Void {}\n"),
Example("func foo() async throws -> () async -> Void { return {} }\n")
],
triggeringExamples: [
Example("let abc: () -> ↓() = {}\n"),
Expand All @@ -27,7 +32,9 @@ struct VoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableRule {
Example("func foo(completion: () -> ↓())\n"),
Example("func foo(completion: () -> ↓( ))\n"),
Example("func foo(completion: () -> ↓(Void))\n"),
Example("let foo: (ConfigurationTests) -> () throws -> ↓()\n")
Example("let foo: (ConfigurationTests) -> () throws -> ↓()\n"),
Example("func foo() async -> ↓()\n"),
Example("func foo() async throws -> ↓()\n")
],
corrections: [
Example("let abc: () -> ↓() = {}\n"): Example("let abc: () -> Void = {}\n"),
Expand All @@ -37,7 +44,8 @@ struct VoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableRule {
Example("func foo(completion: () -> ↓( ))\n"): Example("func foo(completion: () -> Void)\n"),
Example("func foo(completion: () -> ↓(Void))\n"): Example("func foo(completion: () -> Void)\n"),
Example("let foo: (ConfigurationTests) -> () throws -> ↓()\n"):
Example("let foo: (ConfigurationTests) -> () throws -> Void\n")
Example("let foo: (ConfigurationTests) -> () throws -> Void\n"),
Example("func foo() async throws -> ↓()\n"): Example("func foo() async throws -> Void\n")
]
)

Expand All @@ -53,7 +61,7 @@ struct VoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableRule {
let kinds = SyntaxKind.commentAndStringKinds
let parensPattern = "\\(\\s*(?:Void)?\\s*\\)"
let pattern = "->\\s*\(parensPattern)\\s*(?!->)"
let excludingPattern = "(\(pattern))\\s*(throws\\s+)?->"
let excludingPattern = "(\(pattern))\\s*(async\\s+)?(throws\\s+)?->"

return file.match(pattern: pattern, excludingSyntaxKinds: kinds, excludingPattern: excludingPattern,
exclusionMapping: { $0.range(at: 1) }).compactMap {
Expand Down

0 comments on commit 352ffdf

Please sign in to comment.