From 136cdd33a95eadbf2960763a16e5f0642fe1391b Mon Sep 17 00:00:00 2001 From: fummicc1 Date: Sun, 30 Jun 2024 16:49:54 +0900 Subject: [PATCH] Format --- Package.swift | 10 +--- .../Parsers/SwiftSyntaxExtensions.swift | 14 +++--- .../Utils/StringExtensions.swift | 46 +++++++++---------- .../MockoloFramework/Utils/TypeParser.swift | 16 +++---- .../TestFuncThrow/FuncThrowTests.swift | 12 ++--- Tests/TestInit/InitTests.swift | 12 ++--- 6 files changed, 52 insertions(+), 58 deletions(-) diff --git a/Package.swift b/Package.swift index ac8cec53..50a1b112 100644 --- a/Package.swift +++ b/Package.swift @@ -11,14 +11,8 @@ let package = Package( .library(name: "MockoloFramework", targets: ["MockoloFramework"]), ], dependencies: [ - .package( - url: "https://github.com/swiftlang/swift-syntax", - from: "600.0.0-prerelease-2024-06-12" - ), - .package( - url: "https://github.com/apple/swift-argument-parser", - from: "1.2.2" - ), + .package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.0-prerelease-2024-06-12"), + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"), ], targets: [ .executableTarget( diff --git a/Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift b/Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift index 03f5ef3d..94a0df41 100644 --- a/Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift +++ b/Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift @@ -799,11 +799,11 @@ extension Trivia { extension ThrowsClauseSyntax { - var text: String { - if let type { - "\(throwsSpecifier.text)(\(type.description))" - } else { - throwsSpecifier.text - } - } + var text: String { + if let type { + "\(throwsSpecifier.text)(\(type.description))" + } else { + throwsSpecifier.text + } + } } diff --git a/Sources/MockoloFramework/Utils/StringExtensions.swift b/Sources/MockoloFramework/Utils/StringExtensions.swift index 6c29d23f..53579793 100644 --- a/Sources/MockoloFramework/Utils/StringExtensions.swift +++ b/Sources/MockoloFramework/Utils/StringExtensions.swift @@ -110,31 +110,31 @@ extension String { var hasThrowsOrRethrows: Bool { return components(separatedBy: .whitespaces).contains { component in - let hasTypedThrow = hasPrefix(String.throws.withLeftParen) - return component == .throws || hasTypedThrow || component == .rethrows - } + let hasTypedThrow = hasPrefix(String.throws.withLeftParen) + return component == .throws || hasTypedThrow || component == .rethrows + } } - /// Extract Error type in typed-throw. - /// - /// - Note: Because any keyword can appear, it was hard to split by whitespace. - /// - /// - ex - /// ``` - /// throws(any LocalizedError) - /// ↓ should extract - /// any LocalizedError - /// ``` - var typedThrowTypeName: String { - let pattern = #"throws\((?.+)\)"# - guard let regex = try? Regex(pattern, as: (Substring, thrownType: Substring).self) else { - return "" - } - guard let match = firstMatch(of: regex) else { - return "" - } - return String(match.output.thrownType) - } + /// Extract Error type in typed-throw. + /// + /// - Note: Because any keyword can appear, it was hard to split by whitespace. + /// + /// - ex + /// ``` + /// throws(any LocalizedError) + /// ↓ should extract + /// any LocalizedError + /// ``` + var typedThrowTypeName: String { + let pattern = #"throws\((?.+)\)"# + guard let regex = try? Regex(pattern, as: (Substring, thrownType: Substring).self) else { + return "" + } + guard let match = firstMatch(of: regex) else { + return "" + } + return String(match.output.thrownType) + } var hasAsync: Bool { return components(separatedBy: .whitespaces).contains { component in diff --git a/Sources/MockoloFramework/Utils/TypeParser.swift b/Sources/MockoloFramework/Utils/TypeParser.swift index 26aac6bf..daa3ccae 100644 --- a/Sources/MockoloFramework/Utils/TypeParser.swift +++ b/Sources/MockoloFramework/Utils/TypeParser.swift @@ -558,18 +558,18 @@ public final class `Type` { displayableReturnType = "(\(displayableReturnType))" } - let hasThrowsOrRethrows = suffix.hasThrowsOrRethrows - let typedThrowTypeName = suffix.typedThrowTypeName + let hasThrowsOrRethrows = suffix.hasThrowsOrRethrows + let typedThrowTypeName = suffix.typedThrowTypeName - let thrownSuffix: String = if typedThrowTypeName.isNotEmpty { - "\(String.throws)(\(typedThrowTypeName))" - } else { - String.throws - } + let thrownSuffix: String = if typedThrowTypeName.isNotEmpty { + "\(String.throws)(\(typedThrowTypeName))" + } else { + String.throws + } let suffixStr = [ suffix.hasAsync ? String.async + " " : nil, - hasThrowsOrRethrows ? thrownSuffix + " " : nil, + hasThrowsOrRethrows ? thrownSuffix + " " : nil, ].compactMap { $0 }.joined() let typeStr = "((\(displayableParamStr)) \(suffixStr)-> \(displayableReturnType))?" diff --git a/Tests/TestFuncs/TestFuncThrow/FuncThrowTests.swift b/Tests/TestFuncs/TestFuncThrow/FuncThrowTests.swift index 6856f00b..52d1bc15 100644 --- a/Tests/TestFuncs/TestFuncThrow/FuncThrowTests.swift +++ b/Tests/TestFuncs/TestFuncThrow/FuncThrowTests.swift @@ -6,10 +6,10 @@ class FuncThrowTests: MockoloTestCase { dstContent: funcThrowMock) } - func testTypedThrows() { - verify( - srcContent: funcTypedThrow, - dstContent: funcTypedThrowMock - ) - } + func testTypedThrows() { + verify( + srcContent: funcTypedThrow, + dstContent: funcTypedThrowMock + ) + } } diff --git a/Tests/TestInit/InitTests.swift b/Tests/TestInit/InitTests.swift index f5d8af86..898b15a6 100644 --- a/Tests/TestInit/InitTests.swift +++ b/Tests/TestInit/InitTests.swift @@ -42,10 +42,10 @@ class InitTests: MockoloTestCase { ) } - func testThrowableInit() { - verify( - srcContent: throwableInit, - dstContent: throwableInitMock - ) - } + func testThrowableInit() { + verify( + srcContent: throwableInit, + dstContent: throwableInitMock + ) + } }