Skip to content

Commit 3c9424a

Browse files
stephencelisgithub-actions[bot]
authored andcommitted
Run swift-format
1 parent 2754f76 commit 3c9424a

10 files changed

+60
-28
lines changed

Tests/MacroTestingTests/CustomCodableMacroTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class CustomCodableMacroTests: BaseTestCase {
3939
struct Person {
4040
let name: String
4141
@CodableKey("user_age") let age: Int
42-
42+
4343
func randomFunction() {}
4444
}
4545
"""

Tests/MacroTestingTests/FuncUniqueMacroTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
final class FuncUniqueMacroTests: BaseTestCase {
55
override func invokeTest() {
66
withMacroTesting(
7-
macros: [FuncUniqueMacro.self,]
7+
macros: [FuncUniqueMacro.self]
88
) {
99
super.invokeTest()
1010
}

Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,30 @@ public struct AddAsyncMacro: PeerMacro {
4242
}
4343

4444
// This only makes sense void functions
45-
if funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description != "Void" {
45+
if funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, [])
46+
.description != "Void"
47+
{
4648
throw CustomError.message(
4749
"@addAsync requires an function that returns void"
4850
)
4951
}
5052

5153
// Requires a completion handler block as last parameter
52-
guard let completionHandlerParameterAttribute = funcDecl.signature.parameterClause.parameters.last?.type.as(AttributedTypeSyntax.self),
53-
let completionHandlerParameter = completionHandlerParameterAttribute.baseType.as(FunctionTypeSyntax.self)
54+
guard
55+
let completionHandlerParameterAttribute = funcDecl.signature.parameterClause.parameters.last?
56+
.type.as(AttributedTypeSyntax.self),
57+
let completionHandlerParameter = completionHandlerParameterAttribute.baseType.as(
58+
FunctionTypeSyntax.self)
5459
else {
5560
throw CustomError.message(
5661
"@addAsync requires an function that has a completion handler as last parameter"
5762
)
5863
}
5964

6065
// Completion handler needs to return Void
61-
if completionHandlerParameter.returnClause.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description != "Void" {
66+
if completionHandlerParameter.returnClause.type.with(\.leadingTrivia, []).with(
67+
\.trailingTrivia, []
68+
).description != "Void" {
6269
throw CustomError.message(
6370
"@addAsync requires an function that has a completion handler that returns Void"
6471
)
@@ -67,14 +74,18 @@ public struct AddAsyncMacro: PeerMacro {
6774
let returnType = completionHandlerParameter.parameters.first?.type
6875

6976
let isResultReturn = returnType?.children(viewMode: .all).first?.description == "Result"
70-
let successReturnType = isResultReturn ? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument : returnType
77+
let successReturnType =
78+
isResultReturn
79+
? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument
80+
: returnType
7181

7282
// Remove completionHandler and comma from the previous parameter
7383
var newParameterList = funcDecl.signature.parameterClause.parameters
7484
newParameterList.removeLast()
7585
let newParameterListLastParameter = newParameterList.last!
7686
newParameterList.removeLast()
77-
newParameterList.append(newParameterListLastParameter.with(\.trailingTrivia, []).with(\.trailingComma, nil))
87+
newParameterList.append(
88+
newParameterListLastParameter.with(\.trailingTrivia, []).with(\.trailingComma, nil))
7889

7990
// Drop the @addAsync attribute from the new declaration.
8091
let newAttributeList = funcDecl.attributes.filter {
@@ -136,7 +147,9 @@ public struct AddAsyncMacro: PeerMacro {
136147
)
137148
.with(
138149
\.returnClause,
139-
successReturnType != nil ? ReturnClauseSyntax(leadingTrivia: .space, type: successReturnType!.with(\.leadingTrivia, .space)) : nil
150+
successReturnType != nil
151+
? ReturnClauseSyntax(
152+
leadingTrivia: .space, type: successReturnType!.with(\.leadingTrivia, .space)) : nil
140153
) // add result type
141154
.with(
142155
\.parameterClause,

Tests/MacroTestingTests/MacroExamples/AddCompletionHandlerMacro.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public struct AddCompletionHandlerMacro: PeerMacro {
7373
}
7474

7575
// Form the completion handler parameter.
76-
let resultType: TypeSyntax? = funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, [])
76+
let resultType: TypeSyntax? = funcDecl.signature.returnClause?.type.with(\.leadingTrivia, [])
77+
.with(\.trailingTrivia, [])
7778

7879
let completionHandlerParam =
7980
FunctionParameterSyntax(

Tests/MacroTestingTests/MacroExamples/CustomCodable.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ public enum CustomCodable: MemberMacro {
2424
let cases = memberList.compactMap({ member -> String? in
2525
// is a property
2626
guard
27-
let propertyName = member.decl.as(VariableDeclSyntax.self)?.bindings.first?.pattern.as(IdentifierPatternSyntax.self)?.identifier.text
27+
let propertyName = member.decl.as(VariableDeclSyntax.self)?.bindings.first?.pattern.as(
28+
IdentifierPatternSyntax.self)?.identifier.text
2829
else {
2930
return nil
3031
}
3132

3233
// if it has a CodableKey macro on it
33-
if let customKeyMacro = member.decl.as(VariableDeclSyntax.self)?.attributes.first(where: { element in
34-
element.as(AttributeSyntax.self)?.attributeName.as(IdentifierTypeSyntax.self)?.description == "CodableKey"
34+
if let customKeyMacro = member.decl.as(VariableDeclSyntax.self)?.attributes.first(where: {
35+
element in
36+
element.as(AttributeSyntax.self)?.attributeName.as(IdentifierTypeSyntax.self)?.description
37+
== "CodableKey"
3538
}) {
3639

3740
// Uses the value in the Macro
38-
let customKeyValue = customKeyMacro.as(AttributeSyntax.self)!.arguments!.as(LabeledExprListSyntax.self)!.first!.expression
41+
let customKeyValue = customKeyMacro.as(AttributeSyntax.self)!.arguments!.as(
42+
LabeledExprListSyntax.self)!.first!.expression
3943

4044
return "case \(propertyName) = \(customKeyValue)"
4145
} else {

Tests/MacroTestingTests/MacroExamples/MetaEnumMacro.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public struct MetaEnumMacro {
2121
let access: DeclModifierListSyntax.Element?
2222
let parentParamName: TokenSyntax
2323

24-
init(node: AttributeSyntax, declaration: some DeclGroupSyntax, context: some MacroExpansionContext) throws {
24+
init(
25+
node: AttributeSyntax, declaration: some DeclGroupSyntax, context: some MacroExpansionContext
26+
) throws {
2527
guard let enumDecl = declaration.as(EnumDeclSyntax.self) else {
2628
throw DiagnosticsError(diagnostics: [
2729
CaseMacroDiagnostic.notAnEnum(declaration).diagnose(at: Syntax(node))
@@ -94,7 +96,7 @@ extension EnumDeclSyntax {
9496
var caseElements: [EnumCaseElementSyntax] {
9597
memberBlock.members.flatMap { member in
9698
guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
97-
return Array<EnumCaseElementSyntax>()
99+
return [EnumCaseElementSyntax]()
98100
}
99101

100102
return Array(caseDecl.elements)
@@ -110,7 +112,8 @@ extension CaseMacroDiagnostic: DiagnosticMessage {
110112
var message: String {
111113
switch self {
112114
case .notAnEnum(let decl):
113-
return "'@MetaEnum' can only be attached to an enum, not \(decl.descriptiveDeclKind(withArticle: true))"
115+
return
116+
"'@MetaEnum' can only be attached to an enum, not \(decl.descriptiveDeclKind(withArticle: true))"
114117
}
115118
}
116119

Tests/MacroTestingTests/MacroExamples/NewTypeMacro.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ extension NewTypeMacro: MemberMacro {
3030
.expression.as(MemberAccessExprSyntax.self),
3131
let rawType = memberAccessExn.base?.as(DeclReferenceExprSyntax.self)
3232
else {
33-
throw CustomError.message(#"@NewType requires the raw type as an argument, in the form "RawType.self"."#)
33+
throw CustomError.message(
34+
#"@NewType requires the raw type as an argument, in the form "RawType.self"."#)
3435
}
3536

3637
guard let declaration = declaration.as(StructDeclSyntax.self) else {

Tests/MacroTestingTests/MacroExamples/OptionSetMacro.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public struct OptionSetMacro {
9191
stringLiteral.segments.count == 1,
9292
case let .stringSegment(optionsEnumNameString)? = stringLiteral.segments.first
9393
else {
94-
context.diagnose(OptionSetMacroDiagnostic.requiresStringLiteral(optionsEnumNameArgumentLabel).diagnose(at: optionEnumNameArg.expression))
94+
context.diagnose(
95+
OptionSetMacroDiagnostic.requiresStringLiteral(optionsEnumNameArgumentLabel).diagnose(
96+
at: optionEnumNameArg.expression))
9597
return nil
9698
}
9799

@@ -118,12 +120,15 @@ public struct OptionSetMacro {
118120
return nil
119121
}).first
120122
else {
121-
context.diagnose(OptionSetMacroDiagnostic.requiresOptionsEnum(optionsEnumName).diagnose(at: decl))
123+
context.diagnose(
124+
OptionSetMacroDiagnostic.requiresOptionsEnum(optionsEnumName).diagnose(at: decl))
122125
return nil
123126
}
124127

125128
// Retrieve the raw type from the attribute.
126-
guard let genericArgs = attribute.attributeName.as(IdentifierTypeSyntax.self)?.genericArgumentClause,
129+
guard
130+
let genericArgs = attribute.attributeName.as(IdentifierTypeSyntax.self)?
131+
.genericArgumentClause,
127132
let rawType = genericArgs.arguments.first?.argument
128133
else {
129134
context.diagnose(OptionSetMacroDiagnostic.requiresOptionsEnumRawType.diagnose(at: attribute))
@@ -143,13 +148,15 @@ extension OptionSetMacro: ExtensionMacro {
143148
in context: some MacroExpansionContext
144149
) throws -> [ExtensionDeclSyntax] {
145150
// Decode the expansion arguments.
146-
guard let (structDecl, _, _) = decodeExpansion(of: node, attachedTo: declaration, in: context) else {
151+
guard let (structDecl, _, _) = decodeExpansion(of: node, attachedTo: declaration, in: context)
152+
else {
147153
return []
148154
}
149155

150156
// If there is an explicit conformance to OptionSet already, don't add one.
151157
if let inheritedTypes = structDecl.inheritanceClause?.inheritedTypes,
152-
inheritedTypes.contains(where: { inherited in inherited.type.trimmedDescription == "OptionSet" })
158+
inheritedTypes.contains(where: { inherited in inherited.type.trimmedDescription == "OptionSet"
159+
})
153160
{
154161
return []
155162
}
@@ -165,14 +172,16 @@ extension OptionSetMacro: MemberMacro {
165172
in context: some MacroExpansionContext
166173
) throws -> [DeclSyntax] {
167174
// Decode the expansion arguments.
168-
guard let (_, optionsEnum, rawType) = decodeExpansion(of: attribute, attachedTo: decl, in: context) else {
175+
guard
176+
let (_, optionsEnum, rawType) = decodeExpansion(of: attribute, attachedTo: decl, in: context)
177+
else {
169178
return []
170179
}
171180

172181
// Find all of the case elements.
173182
let caseElements = optionsEnum.memberBlock.members.flatMap { member in
174183
guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
175-
return Array<EnumCaseElementSyntax>()
184+
return [EnumCaseElementSyntax]()
176185
}
177186

178187
return Array(caseDecl.elements)

Tests/MacroTestingTests/MacroExamples/WrapStoredPropertiesMacro.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public struct WrapStoredPropertiesMacro: MemberAttributeMacro {
4343
stringLiteral.segments.count == 1,
4444
case let .stringSegment(wrapperName)? = stringLiteral.segments.first
4545
else {
46-
throw CustomError.message("macro requires a string literal containing the name of an attribute")
46+
throw CustomError.message(
47+
"macro requires a string literal containing the name of an attribute")
4748
}
4849

4950
return [

Tests/MacroTestingTests/MemberDeprecatedMacroTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ final class MemberDepreacatedMacroTests: XCTestCase {
1414
@memberDeprecated
1515
public struct SomeStruct {
1616
typealias MacroName = String
17-
17+
1818
public var oldProperty: Int = 420
19-
19+
2020
func oldMethod() {
2121
print("This is an old method.")
2222
}

0 commit comments

Comments
 (0)