From 352ffdfc5779cae28eb0c4990711d06823ef93cb Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Fri, 17 Feb 2023 21:39:32 +0100 Subject: [PATCH] Fix void_return rule to support async and async throws functions (#4772) --- CHANGELOG.md | 4 ++++ .../Rules/Style/VoidReturnRule.swift | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02d218ad14..f284ecf8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Source/SwiftLintFramework/Rules/Style/VoidReturnRule.swift b/Source/SwiftLintFramework/Rules/Style/VoidReturnRule.swift index 4e369def96..e8c8b86987 100644 --- a/Source/SwiftLintFramework/Rules/Style/VoidReturnRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/VoidReturnRule.swift @@ -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"), @@ -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"), @@ -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") ] ) @@ -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 {