From 1767dab4858a310719fdf44e6c8dd9dc371503f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 21 Sep 2024 13:53:30 +0200 Subject: [PATCH] Add Swift 6 presentation of `map(_:)` type (#5804) --- .../Rules/Lint/TypesafeArrayInitRule.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift index 0d7ea85937..faa619e479 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift @@ -51,10 +51,16 @@ struct TypesafeArrayInitRule: AnalyzerRule { ) private static let parentRule = ArrayInitRule() - private static let mapTypePattern = regex(""" - \\Q \ - \\Q(Self) -> ((Self.Element) throws -> T) throws -> [T]\\E - """) + private static let mapTypePatterns = [ + regex(""" + \\Q \ + \\Q(Self) -> ((Self.Element) throws -> T) throws -> [T]\\E + """), + regex(""" + \\Q (Self) -> ((Self.Element) throws(E) -> T) throws(E) -> [T]\\E + """), + ] func validate(file: SwiftLintFile, compilerArguments: [String]) -> [StyleViolation] { guard let filePath = file.path else { @@ -83,7 +89,9 @@ struct TypesafeArrayInitRule: AnalyzerRule { if let isSystem = pointee["key.is_system"], isSystem.isEqualTo(true), let name = pointee["key.name"], name.isEqualTo("map(_:)"), let typeName = pointee["key.typename"] as? String { - return Self.mapTypePattern.numberOfMatches(in: typeName, range: typeName.fullNSRange) == 1 + return Self.mapTypePatterns.contains { + $0.numberOfMatches(in: typeName, range: typeName.fullNSRange) == 1 + } } return false }