Skip to content

Commit

Permalink
Improve formatting of initializer fixit (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed authored Dec 29, 2024
1 parent 93bf009 commit 85321d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Sources/SafeDICore/Models/Initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,16 @@ public struct Initializer: Codable, Hashable, Sendable {
signature: FunctionSignatureSyntax(
parameterClause: FunctionParameterClauseSyntax(
parameters: FunctionParameterListSyntax(itemsBuilder: {
for functionParameter in dependencies.initializerFunctionParameters {
for functionParameter in dependencies.initializerFunctionParameters.enumerated().map({ index, parameter in
var parameter = parameter
if dependencies.initializerFunctionParameters.endIndex > 1 {
if index == 0 {
parameter.leadingTrivia = .newline
}
parameter.trailingTrivia = .newline
}
return parameter
}) {
functionParameter
}
})
Expand Down
22 changes: 18 additions & 4 deletions Tests/SafeDIMacrosTests/InstantiableMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,11 @@ import SafeDICore
"""
@Instantiable
public struct ExampleService: Instantiable {
public init(forwardedA: ForwardedA, receivedA: ReceivedA, receivedB: ReceivedB) {
public init(
forwardedA: ForwardedA,
receivedA: ReceivedA,
receivedB: ReceivedB
) {
self.forwardedA = forwardedA
self.receivedA = receivedA
self.receivedB = receivedB
Expand All @@ -1241,7 +1245,11 @@ import SafeDICore
} expansion: {
"""
public struct ExampleService: Instantiable {
public init(forwardedA: ForwardedA, receivedA: ReceivedA, receivedB: ReceivedB) {
public init(
forwardedA: ForwardedA,
receivedA: ReceivedA,
receivedB: ReceivedB
) {
self.forwardedA = forwardedA
self.receivedA = receivedA
self.receivedB = receivedB
Expand Down Expand Up @@ -1291,7 +1299,10 @@ import SafeDICore
"""
@Instantiable
public final class UserService: Instantiable {
public init(userID: String, userName: String) {
public init(
userID: String,
userName: String
) {
self.userID = userID
self.userName = userName
}
Expand All @@ -1306,7 +1317,10 @@ import SafeDICore
} expansion: {
"""
public final class UserService: Instantiable {
public init(userID: String, userName: String) {
public init(
userID: String,
userName: String
) {
self.userID = userID
self.userName = userName
}
Expand Down

0 comments on commit 85321d5

Please sign in to comment.