diff --git a/Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift b/Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift index da9faa6..674e98e 100644 --- a/Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift +++ b/Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift @@ -42,15 +42,20 @@ public struct AddAsyncMacro: PeerMacro { } // This only makes sense void functions - if funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description != "Void" { + if funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []) + .description != "Void" + { throw CustomError.message( "@addAsync requires an function that returns void" ) } // Requires a completion handler block as last parameter - guard let completionHandlerParameterAttribute = funcDecl.signature.parameterClause.parameters.last?.type.as(AttributedTypeSyntax.self), - let completionHandlerParameter = completionHandlerParameterAttribute.baseType.as(FunctionTypeSyntax.self) + guard + let completionHandlerParameterAttribute = funcDecl.signature.parameterClause.parameters.last? + .type.as(AttributedTypeSyntax.self), + let completionHandlerParameter = completionHandlerParameterAttribute.baseType.as( + FunctionTypeSyntax.self) else { throw CustomError.message( "@addAsync requires an function that has a completion handler as last parameter" @@ -58,7 +63,9 @@ public struct AddAsyncMacro: PeerMacro { } // Completion handler needs to return Void - if completionHandlerParameter.returnClause.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description != "Void" { + if completionHandlerParameter.returnClause.type.with(\.leadingTrivia, []).with( + \.trailingTrivia, [] + ).description != "Void" { throw CustomError.message( "@addAsync requires an function that has a completion handler that returns Void" ) @@ -67,14 +74,18 @@ public struct AddAsyncMacro: PeerMacro { let returnType = completionHandlerParameter.parameters.first?.type let isResultReturn = returnType?.children(viewMode: .all).first?.description == "Result" - let successReturnType = isResultReturn ? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument : returnType + let successReturnType = + isResultReturn + ? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument + : returnType // Remove completionHandler and comma from the previous parameter var newParameterList = funcDecl.signature.parameterClause.parameters newParameterList.removeLast() let newParameterListLastParameter = newParameterList.last! newParameterList.removeLast() - newParameterList.append(newParameterListLastParameter.with(\.trailingTrivia, []).with(\.trailingComma, nil)) + newParameterList.append( + newParameterListLastParameter.with(\.trailingTrivia, []).with(\.trailingComma, nil)) // Drop the @addAsync attribute from the new declaration. let newAttributeList = funcDecl.attributes.filter { @@ -136,7 +147,9 @@ public struct AddAsyncMacro: PeerMacro { ) .with( \.returnClause, - successReturnType != nil ? ReturnClauseSyntax(leadingTrivia: .space, type: successReturnType!.with(\.leadingTrivia, .space)) : nil + successReturnType != nil + ? ReturnClauseSyntax( + leadingTrivia: .space, type: successReturnType!.with(\.leadingTrivia, .space)) : nil ) // add result type .with( \.parameterClause, diff --git a/Tests/MacroTestingTests/MacroExamples/AddCompletionHandlerMacro.swift b/Tests/MacroTestingTests/MacroExamples/AddCompletionHandlerMacro.swift index 3f1d833..a70aa08 100644 --- a/Tests/MacroTestingTests/MacroExamples/AddCompletionHandlerMacro.swift +++ b/Tests/MacroTestingTests/MacroExamples/AddCompletionHandlerMacro.swift @@ -73,7 +73,8 @@ public struct AddCompletionHandlerMacro: PeerMacro { } // Form the completion handler parameter. - let resultType: TypeSyntax? = funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []) + let resultType: TypeSyntax? = funcDecl.signature.returnClause?.type.with(\.leadingTrivia, []) + .with(\.trailingTrivia, []) let completionHandlerParam = FunctionParameterSyntax( diff --git a/Tests/MacroTestingTests/MacroExamples/CustomCodable.swift b/Tests/MacroTestingTests/MacroExamples/CustomCodable.swift index 1b4fffe..a3b1d6a 100644 --- a/Tests/MacroTestingTests/MacroExamples/CustomCodable.swift +++ b/Tests/MacroTestingTests/MacroExamples/CustomCodable.swift @@ -24,18 +24,22 @@ public enum CustomCodable: MemberMacro { let cases = memberList.compactMap({ member -> String? in // is a property guard - let propertyName = member.decl.as(VariableDeclSyntax.self)?.bindings.first?.pattern.as(IdentifierPatternSyntax.self)?.identifier.text + let propertyName = member.decl.as(VariableDeclSyntax.self)?.bindings.first?.pattern.as( + IdentifierPatternSyntax.self)?.identifier.text else { return nil } // if it has a CodableKey macro on it - if let customKeyMacro = member.decl.as(VariableDeclSyntax.self)?.attributes.first(where: { element in - element.as(AttributeSyntax.self)?.attributeName.as(IdentifierTypeSyntax.self)?.description == "CodableKey" + if let customKeyMacro = member.decl.as(VariableDeclSyntax.self)?.attributes.first(where: { + element in + element.as(AttributeSyntax.self)?.attributeName.as(IdentifierTypeSyntax.self)?.description + == "CodableKey" }) { // Uses the value in the Macro - let customKeyValue = customKeyMacro.as(AttributeSyntax.self)!.arguments!.as(LabeledExprListSyntax.self)!.first!.expression + let customKeyValue = customKeyMacro.as(AttributeSyntax.self)!.arguments!.as( + LabeledExprListSyntax.self)!.first!.expression return "case \(propertyName) = \(customKeyValue)" } else { diff --git a/Tests/MacroTestingTests/MacroExamples/MetaEnumMacro.swift b/Tests/MacroTestingTests/MacroExamples/MetaEnumMacro.swift index 4120d05..22ac266 100644 --- a/Tests/MacroTestingTests/MacroExamples/MetaEnumMacro.swift +++ b/Tests/MacroTestingTests/MacroExamples/MetaEnumMacro.swift @@ -21,7 +21,9 @@ public struct MetaEnumMacro { let access: DeclModifierListSyntax.Element? let parentParamName: TokenSyntax - init(node: AttributeSyntax, declaration: some DeclGroupSyntax, context: some MacroExpansionContext) throws { + init( + node: AttributeSyntax, declaration: some DeclGroupSyntax, context: some MacroExpansionContext + ) throws { guard let enumDecl = declaration.as(EnumDeclSyntax.self) else { throw DiagnosticsError(diagnostics: [ CaseMacroDiagnostic.notAnEnum(declaration).diagnose(at: Syntax(node)) @@ -94,7 +96,7 @@ extension EnumDeclSyntax { var caseElements: [EnumCaseElementSyntax] { memberBlock.members.flatMap { member in guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else { - return Array() + return [EnumCaseElementSyntax]() } return Array(caseDecl.elements) @@ -110,7 +112,8 @@ extension CaseMacroDiagnostic: DiagnosticMessage { var message: String { switch self { case .notAnEnum(let decl): - return "'@MetaEnum' can only be attached to an enum, not \(decl.descriptiveDeclKind(withArticle: true))" + return + "'@MetaEnum' can only be attached to an enum, not \(decl.descriptiveDeclKind(withArticle: true))" } } diff --git a/Tests/MacroTestingTests/MacroExamples/NewTypeMacro.swift b/Tests/MacroTestingTests/MacroExamples/NewTypeMacro.swift index 1740aaf..41e8cdd 100644 --- a/Tests/MacroTestingTests/MacroExamples/NewTypeMacro.swift +++ b/Tests/MacroTestingTests/MacroExamples/NewTypeMacro.swift @@ -30,7 +30,8 @@ extension NewTypeMacro: MemberMacro { .expression.as(MemberAccessExprSyntax.self), let rawType = memberAccessExn.base?.as(DeclReferenceExprSyntax.self) else { - throw CustomError.message(#"@NewType requires the raw type as an argument, in the form "RawType.self"."#) + throw CustomError.message( + #"@NewType requires the raw type as an argument, in the form "RawType.self"."#) } guard let declaration = declaration.as(StructDeclSyntax.self) else { diff --git a/Tests/MacroTestingTests/MacroExamples/WrapStoredPropertiesMacro.swift b/Tests/MacroTestingTests/MacroExamples/WrapStoredPropertiesMacro.swift index d885331..5f34c39 100644 --- a/Tests/MacroTestingTests/MacroExamples/WrapStoredPropertiesMacro.swift +++ b/Tests/MacroTestingTests/MacroExamples/WrapStoredPropertiesMacro.swift @@ -43,7 +43,8 @@ public struct WrapStoredPropertiesMacro: MemberAttributeMacro { stringLiteral.segments.count == 1, case let .stringSegment(wrapperName)? = stringLiteral.segments.first else { - throw CustomError.message("macro requires a string literal containing the name of an attribute") + throw CustomError.message( + "macro requires a string literal containing the name of an attribute") } return [