From f32bc1f337d6e158181f5ce4d31695d9af5c229a Mon Sep 17 00:00:00 2001 From: Martin Hosna Date: Mon, 29 Aug 2022 18:56:35 +0200 Subject: [PATCH] RedundantDiscardableLetRule should not produce warning when used with async (#4143) handle situation with async let _ = .... let can not be removed from "async let _ = ..." because removing it produces invalid swift syntax Co-authored-by: Martin Hosna --- .../Rules/Style/RedundantDiscardableLetRule.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/Style/RedundantDiscardableLetRule.swift b/Source/SwiftLintFramework/Rules/Style/RedundantDiscardableLetRule.swift index 614731546..a17e62674 100644 --- a/Source/SwiftLintFramework/Rules/Style/RedundantDiscardableLetRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/RedundantDiscardableLetRule.swift @@ -16,7 +16,8 @@ public struct RedundantDiscardableLetRule: SubstitutionCorrectableRule, Configur Example("if let _ = foo() { }\n"), Example("guard let _ = foo() else { return }\n"), Example("let _: ExplicitType = foo()"), - Example("while let _ = SplashStyle(rawValue: maxValue) { maxValue += 1 }\n") + Example("while let _ = SplashStyle(rawValue: maxValue) { maxValue += 1 }\n"), + Example("async let _ = await foo()") ], triggeringExamples: [ Example("↓let _ = foo()\n"), @@ -42,7 +43,7 @@ public struct RedundantDiscardableLetRule: SubstitutionCorrectableRule, Configur public func violationRanges(in file: SwiftLintFile) -> [NSRange] { let contents = file.stringView - return file.match(pattern: "let\\s+_\\b", with: [.keyword, .keyword]).filter { range in + return file.match(pattern: "(?