Skip to content

Commit ec2862d

Browse files
authored
Strip trailing comments from endpoints. (#347)
1 parent a4480ca commit ec2862d

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ extension PatternBindingListSyntax {
225225
identifier: identifier.identifier.privatePrefixed(prefix),
226226
trailingTrivia: identifier.trailingTrivia
227227
),
228-
typeAnnotation: binding.typeAnnotation,
228+
typeAnnotation: binding.typeAnnotation?.with(\.trailingTrivia, ""),
229229
initializer: InitializerClauseSyntax(value: unimplementedDefault),
230230
accessorBlock: binding.accessorBlock,
231-
trailingComma: binding.trailingComma,
232-
trailingTrivia: binding.trailingTrivia
231+
trailingComma: binding.trailingComma
233232
)
234233
}
235234
}
@@ -284,8 +283,7 @@ extension VariableDeclSyntax {
284283
trailingTrivia: .space,
285284
presence: .present
286285
),
287-
bindings: bindings.privatePrefixed(prefix, unimplementedDefault: unimplementedDefault),
288-
trailingTrivia: trailingTrivia
286+
bindings: bindings.privatePrefixed(prefix, unimplementedDefault: unimplementedDefault)
289287
)
290288
}
291289
}

Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift

+35-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import XCTest
55
final class DependencyClientMacroTests: BaseTestCase {
66
override func invokeTest() {
77
withMacroTesting(
8-
// isRecording: true,
8+
record: .failed,
99
macros: [DependencyClientMacro.self]
1010
) {
1111
super.invokeTest()
1212
}
1313
}
1414

1515
func testBasics() {
16-
1716
assertMacro {
1817
"""
1918
@DependencyClient
@@ -1072,4 +1071,38 @@ final class DependencyClientMacroTests: BaseTestCase {
10721071
"""
10731072
}
10741073
}
1074+
1075+
func testComments() {
1076+
assertMacro {
1077+
"""
1078+
@DependencyClient
1079+
struct Client {
1080+
var config: Bool = false // This is a comment
1081+
var endpoint: () -> Void // And this is a comment
1082+
}
1083+
"""
1084+
} expansion: {
1085+
"""
1086+
struct Client {
1087+
var config: Bool = false // This is a comment
1088+
@DependencyEndpoint
1089+
var endpoint: () -> Void // And this is a comment
1090+
1091+
init(
1092+
config: Bool = false,
1093+
endpoint: @escaping () -> Void
1094+
) {
1095+
self.config = config
1096+
self.endpoint = endpoint
1097+
}
1098+
1099+
init(
1100+
config: Bool = false
1101+
) {
1102+
self.config = config
1103+
}
1104+
}
1105+
"""
1106+
}
1107+
}
10751108
}

Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift

+33-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import XCTest
55
final class DependencyEndpointMacroTests: BaseTestCase {
66
override func invokeTest() {
77
withMacroTesting(
8-
// isRecording: true,
8+
record: .failed,
99
macros: [DependencyEndpointMacro.self]
1010
) {
1111
super.invokeTest()
@@ -1010,4 +1010,36 @@ final class DependencyEndpointMacroTests: BaseTestCase {
10101010
"""#
10111011
}
10121012
}
1013+
1014+
func testComments() {
1015+
assertMacro {
1016+
"""
1017+
struct Client {
1018+
@DependencyEndpoint
1019+
var endpoint: () -> Void // This is a comment
1020+
}
1021+
"""
1022+
} expansion: {
1023+
#"""
1024+
struct Client {
1025+
var endpoint: () -> Void // This is a comment {
1026+
@storageRestrictions(initializes: _endpoint)
1027+
init(initialValue) {
1028+
_endpoint = initialValue
1029+
}
1030+
get {
1031+
_endpoint
1032+
}
1033+
set {
1034+
_endpoint = newValue
1035+
}
1036+
}
1037+
1038+
private var _endpoint: () -> Void = {
1039+
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
1040+
}
1041+
}
1042+
"""#
1043+
}
1044+
}
10131045
}

0 commit comments

Comments
 (0)