Skip to content

Commit 35acd94

Browse files
stephencelisgithub-actions[bot]
authored andcommitted
Run swift-format
1 parent 0727d7f commit 35acd94

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

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/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 [

0 commit comments

Comments
 (0)