Description
Currently SwiftBasicFormat defaults to format initializer declaration as init (…) and init ?(…).
This is diverged from the common practice as well as the Swift book.
eg. https://github.com/apple/swift-syntax/blob/aeb2ff511cd0a4e37f794a93004f55fb03be2633/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift#L93-L95
Steps to Reproduce
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftBasicFormat
class CodeGenerationFormat: BasicFormat {
override var indentation: TriviaPiece { .spaces(indentationLevel * 2) }
}
let sourceFile = SourceFile {
StructDecl("public struct SimpleError: Error") {
VariableDecl("private let code: Int")
InitializerDecl("""
public init?(errorCode: Int) {
guard errorCode > 0 else { return nil }
self.code = errorCode
}
""")
}
}
print(sourceFile.formatted(using: CodeGenerationFormat()))
Output:
public struct SimpleError: Error {
private let code: Int
public init ?(errorCode: Int) {
guard errorCode > 0 else {
return nil
}
self.code = errorCode
}
}
Description
Currently
SwiftBasicFormatdefaults to format initializer declaration asinit (…)andinit ?(…).This is diverged from the common practice as well as the Swift book.
eg. https://github.com/apple/swift-syntax/blob/aeb2ff511cd0a4e37f794a93004f55fb03be2633/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift#L93-L95
Steps to Reproduce
Output: