diff --git a/Package.swift b/Package.swift index f3d5d6870d..b7352bd3c5 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,6 @@ let package = Package( .package(url: "https://github.com/swiftlang/swift-syntax.git", "509.1.0"..<"602.0.0"), .package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"), - .package(url: "https://github.com/swiftlang/swift-format", from: "600.0.0"), .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"), ], targets: [ @@ -75,7 +74,6 @@ let package = Package( dependencies: [ "PluginCore", "MacroPlugin", "MetaCodable", "HelperCoders", .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"), - .product(name: "SwiftSyntaxMacrosGenericTestSupport", package: "swift-syntax"), ], plugins: ["MetaProtocolCodable"] ), diff --git a/Package@swift-5.swift b/Package@swift-5.swift index 899b28c5c4..b0a38bf069 100644 --- a/Package@swift-5.swift +++ b/Package@swift-5.swift @@ -23,7 +23,6 @@ let package = Package( .package(url: "https://github.com/swiftlang/swift-syntax.git", "509.1.0"..<"602.0.0"), .package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"), - .package(url: "https://github.com/swiftlang/swift-format", from: "600.0.0"), ], targets: [ // MARK: Core @@ -86,7 +85,6 @@ let package = Package( dependencies: [ "PluginCore", "MacroPlugin", "MetaCodable", "HelperCoders", "Testing", .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"), - .product(name: "SwiftSyntaxMacrosGenericTestSupport", package: "swift-syntax"), ], plugins: ["MetaProtocolCodable"] ), diff --git a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-01.swift b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-01.swift index 4d185a8e1a..191e5b1185 100644 --- a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-01.swift +++ b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-01.swift @@ -1,10 +1,10 @@ -import MetaCodable import HelperCoders +import MetaCodable @Codable(commonStrategies: [.codedBy(.valueCoder())]) struct User { - let id: Int // Will use ValueCoder - let name: String // Will use ValueCoder - let active: Bool // Will use ValueCoder - let score: Double // Will use ValueCoder + let id: Int // Will use ValueCoder + let name: String // Will use ValueCoder + let active: Bool // Will use ValueCoder + let score: Double // Will use ValueCoder } diff --git a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-02.swift b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-02.swift index 2247486570..d35f372779 100644 --- a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-02.swift +++ b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/CommonStrategies-02.swift @@ -1,14 +1,16 @@ -import MetaCodable import HelperCoders +import MetaCodable @Codable(commonStrategies: [ .codedBy(.valueCoder()), - .codedBy(.sequenceCoder(elementHelper: .valueCoder(), configuration: .lossy)) + .codedBy( + .sequenceCoder(elementHelper: .valueCoder(), configuration: .lossy + ), ]) struct User { - let id: Int // Will use ValueCoder - let tags: [String] // Will use SequenceCoder with ValueCoder - let scores: [Double] // Will use SequenceCoder with ValueCoder + let id: Int // Will use ValueCoder + let tags: [String] // Will use SequenceCoder with ValueCoder + let scores: [Double] // Will use SequenceCoder with ValueCoder @CodedBy(ISO8601DateCoder()) // Override with specific coder let createdAt: Date } diff --git a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-01.swift b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-01.swift index 12d1f5a85e..574fe1f832 100644 --- a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-01.swift +++ b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-01.swift @@ -1,5 +1,5 @@ -import MetaCodable import HelperCoders +import MetaCodable @Codable struct Product { diff --git a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-03.swift b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-03.swift index 912f6b6177..d7e6fa137a 100644 --- a/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-03.swift +++ b/Sources/MetaCodable/MetaCodable.docc/Tutorials/Helper/Code/Product-03.swift @@ -1,5 +1,5 @@ -import MetaCodable import HelperCoders +import MetaCodable @Codable(commonStrategies: [.codedBy(.valueCoder())]) struct Product { diff --git a/Sources/PluginCore/Attributes/CodedAs.swift b/Sources/PluginCore/Attributes/CodedAs.swift index 7ed5755862..4e2021ea03 100644 --- a/Sources/PluginCore/Attributes/CodedAs.swift +++ b/Sources/PluginCore/Attributes/CodedAs.swift @@ -24,7 +24,8 @@ package struct CodedAs: PropertyAttribute { /// the identifier to this type. var type: TypeSyntax? { return node.attributeName.as(IdentifierTypeSyntax.self)? - .genericArgumentClause?.arguments.first?.argument.as(TypeSyntax.self) + .genericArgumentClause?.arguments + .first?.argument.as(TypeSyntax.self) } /// Creates a new instance with the provided node. diff --git a/Sources/TestingMacroPlugin/Expression.swift b/Sources/TestingMacroPlugin/Expression.swift index 7966451385..0151403be9 100644 --- a/Sources/TestingMacroPlugin/Expression.swift +++ b/Sources/TestingMacroPlugin/Expression.swift @@ -135,3 +135,11 @@ struct ExpectThrows: ExpressionMacro { ) } } + +#if !canImport(SwiftSyntax510) +extension FreestandingMacroExpansionSyntax { + var arguments: LabeledExprListSyntax { + return self.argumentList + } +} +#endif diff --git a/Tests/MetaCodableTests/Codable/CommonStrategiesValueCoderTests.swift b/Tests/MetaCodableTests/Codable/CommonStrategiesValueCoderTests.swift index c13dc8ec9c..01b6c21ed8 100644 --- a/Tests/MetaCodableTests/Codable/CommonStrategiesValueCoderTests.swift +++ b/Tests/MetaCodableTests/Codable/CommonStrategiesValueCoderTests.swift @@ -414,7 +414,9 @@ struct CommonStrategiesValueCoderTests { // Test encoding let encoder = JSONEncoder() encoder.outputFormatting = .sortedKeys - let encoded = try String(data: encoder.encode(status), encoding: .utf8) + let encoded = try String( + data: encoder.encode(status), encoding: .utf8 + ) #expect(encoded == #"{"since":"20250520","type":"active"}"#) // Test decoding other cases with numeric values @@ -425,7 +427,9 @@ struct CommonStrategiesValueCoderTests { } """ let inactiveData = try #require(inactiveJson.data(using: .utf8)) - let inactiveStatus = try decoder.decode(Status.self, from: inactiveData) + let inactiveStatus = try decoder.decode( + Status.self, from: inactiveData + ) if case .inactive(let reason) = inactiveStatus { #expect(reason == "404") } else { @@ -440,7 +444,9 @@ struct CommonStrategiesValueCoderTests { } """ let pendingData = try #require(pendingJson.data(using: .utf8)) - let pendingStatus = try decoder.decode(Status.self, from: pendingData) + let pendingStatus = try decoder.decode( + Status.self, from: pendingData + ) if case .pending(let until) = pendingStatus { #expect(until == "20251231") } else { @@ -553,16 +559,20 @@ struct CommonStrategiesValueCoderTests { let jsonData = try #require(json.data(using: .utf8)) let decoder = JSONDecoder() - let model = try decoder.decode(ModelWithOverride.self, from: jsonData) + let model = try decoder.decode( + ModelWithOverride.self, from: jsonData + ) - #expect(model.id == 42) // Due to CustomIntCoder doubling the value - #expect(model.count == 42) // Normal ValueCoder behavior + #expect(model.id == 42) // Due to CustomIntCoder doubling the value + #expect(model.count == 42) // Normal ValueCoder behavior // Test encoding let encoder = JSONEncoder() encoder.outputFormatting = .sortedKeys - let encoded = try String(data: encoder.encode(model), encoding: .utf8) - #expect(encoded == #"{"count":42,"id":"21"}"#) // CustomIntCoder halves the value for id + let encoded = try String( + data: encoder.encode(model), encoding: .utf8 + ) + #expect(encoded == #"{"count":42,"id":"21"}"#) // CustomIntCoder halves the value for id } @Test @@ -632,11 +642,11 @@ fileprivate struct CustomIntCoder: HelperCoder { debugDescription: "Could not decode value" ) } - return intValue * 2 // Double the value during decoding + return intValue * 2 // Double the value during decoding } func encode(_ value: Int, to encoder: Encoder) throws { var container = encoder.singleValueContainer() - try container.encode(String(value / 2)) // Halve the value during encoding + try container.encode(String(value / 2)) // Halve the value during encoding } } diff --git a/package.json b/package.json index 72b07dfaf8..584895ef37 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "METACODABLE_CI=true npm exec --package=swiftylab-ci -- test.mjs", "archive": "echo implement", "generate": "echo implement", - "format": "METACODABLE_CI=true npm exec --package=swiftylab-ci -- format.mjs", + "format": "METACODABLE_CI=true swift format --in-place --recursive .", "pod-lint": "Utils/pod_lint.rb", "preview-doc": "METACODABLE_CI=true SPI_GENERATE_DOCS=true npm exec --package=swiftylab-ci -- preview-doc.mjs MetaCodable", "build-doc": "METACODABLE_CI=true SPI_GENERATE_DOCS=true npm exec --package=swiftylab-ci -- build-doc.mjs MetaCodable HelperCoders",