Skip to content

Commit 919ae85

Browse files
committed
Standardize indentation and code formatting in macro examples
1 parent 96acf68 commit 919ae85

File tree

10 files changed

+93
-99
lines changed

10 files changed

+93
-99
lines changed

Examples/Sources/MacroExamples/Implementation/ComplexMacros/DictionaryIndirectionMacro.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,14 @@ public struct DictionaryStoragePropertyMacro: AccessorMacro {
8181

8282
return [
8383
"""
84-
85-
get {
86-
_storage[\(literal: identifier.text), default: \(defaultValue)] as! \(type)
87-
}
84+
get {
85+
_storage[\(literal: identifier.text), default: \(defaultValue)] as! \(type)
86+
}
8887
""",
8988
"""
90-
91-
set {
92-
_storage[\(literal: identifier.text)] = newValue
93-
}
89+
set {
90+
_storage[\(literal: identifier.text)] = newValue
91+
}
9492
""",
9593
]
9694
}

Examples/Sources/MacroExamples/Implementation/Member/CustomCodable.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ public enum CustomCodable: MemberMacro {
4444
})
4545

4646
let codingKeys: DeclSyntax = """
47-
48-
enum CodingKeys: String, CodingKey {
49-
\(raw: cases.joined(separator: "\n"))
50-
}
51-
47+
enum CodingKeys: String, CodingKey {
48+
\(raw: cases.joined(separator: "\n"))
49+
}
5250
"""
5351

5452
return [codingKeys]

Examples/Sources/MacroExamples/Implementation/Member/MetaEnumMacro.swift

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,39 @@ public struct MetaEnumMacro {
4141

4242
func makeMetaEnum() -> DeclSyntax {
4343
// FIXME: Why does this need to be a string to make trailing trivia work properly?
44-
let caseDecls = childCases.map { childCase in
45-
" case \(childCase.name)"
46-
}.joined(separator: "\n")
44+
let caseDecls =
45+
childCases
46+
.map { childCase in
47+
" case \(childCase.name)"
48+
}
49+
.joined(separator: "\n")
4750

4851
return """
49-
50-
\(access)enum Meta {
52+
\(access)enum Meta {
5153
\(raw: caseDecls)
5254
\(makeMetaInit())
53-
}
54-
55+
}
5556
"""
5657
}
5758

5859
func makeMetaInit() -> DeclSyntax {
5960
// FIXME: Why does this need to be a string to make trailing trivia work properly?
60-
let caseStatements = childCases.map { childCase in
61-
"""
62-
case .\(childCase.name):
63-
self = .\(childCase.name)
64-
"""
65-
}.joined(separator: "\n")
61+
let caseStatements =
62+
childCases
63+
.map { childCase in
64+
"""
65+
case .\(childCase.name):
66+
self = .\(childCase.name)
67+
"""
68+
}
69+
.joined(separator: "\n")
6670

6771
return """
68-
69-
\(access)init(_ \(parentParamName): \(parentTypeName)) {
70-
switch \(parentParamName) {
72+
\(access)init(_ \(parentParamName): \(parentTypeName)) {
73+
switch \(parentParamName) {
7174
\(raw: caseStatements)
72-
}
73-
}
75+
}
76+
}
7477
"""
7578
}
7679
}

Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public struct AddAsyncMacro: PeerMacro {
101101

102102
let switchBody: ExprSyntax =
103103
"""
104-
switch returnValue {
105-
case .success(let value):
106-
continuation.resume(returning: value)
107-
case .failure(let error):
108-
continuation.resume(throwing: error)
109-
}
104+
switch returnValue {
105+
case .success(let value):
106+
continuation.resume(returning: value)
107+
case .failure(let error):
108+
continuation.resume(throwing: error)
109+
}
110110
"""
111111

112112
let newBody: ExprSyntax =
@@ -115,8 +115,7 @@ public struct AddAsyncMacro: PeerMacro {
115115
\(raw: isResultReturn ? "try await withCheckedThrowingContinuation { continuation in" : "await withCheckedContinuation { continuation in")
116116
\(raw: funcDecl.name)(\(raw: callArguments.joined(separator: ", "))) { \(raw: returnType != nil ? "returnValue in" : "")
117117
118-
\(raw: isResultReturn ? switchBody : "continuation.resume(returning: \(raw: returnType != nil ? "returnValue" : "()"))")
119-
118+
\(raw: isResultReturn ? switchBody : "continuation.resume(returning: \(raw: returnType != nil ? "returnValue" : "()"))")
120119
}
121120
}
122121

Examples/Sources/MacroExamples/Playground/ExpressionMacrosPlayground.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func runExpressionMacrosPlayground() {
4545
// malformed an error is emitted. Otherwise a non-optional URL is expanded.
4646
print(#URL("https://swift.org/"))
4747

48-
let domain = "domain.com"
48+
// let domain = "domain.com"
4949
//print(#URL("https://\(domain)/api/path")) // error: #URL requires a static string literal
5050
//print(#URL("https://not a url.com")) // error: Malformed url
5151

Examples/Tests/MacroExamples/Implementation/ComplexMacros/DictionaryIndirectionMacroTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ final class DictionaryStorageMacroTests: XCTestCase {
3434
struct Point {
3535
var x: Int = 1 {
3636
get {
37-
_storage["x", default: 1] as! Int
38-
}
37+
_storage["x", default: 1] as! Int
38+
}
3939
set {
40-
_storage["x"] = newValue
41-
}
40+
_storage["x"] = newValue
41+
}
4242
}
4343
var y: Int = 2 {
4444
get {
45-
_storage["y", default: 2] as! Int
46-
}
45+
_storage["y", default: 2] as! Int
46+
}
4747
set {
48-
_storage["y"] = newValue
49-
}
48+
_storage["y"] = newValue
49+
}
5050
}
5151
5252
var _storage: [String: Any] = [:]

Examples/Tests/MacroExamples/Implementation/ComplexMacros/OptionSetMacroTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ final class OptionSetMacroTests: XCTestCase {
5959
}
6060
6161
static let nextDay: Self =
62-
Self (rawValue: 1 << Options.nextDay.rawValue)
62+
Self(rawValue: 1 << Options.nextDay.rawValue)
6363
6464
static let secondDay: Self =
65-
Self (rawValue: 1 << Options.secondDay.rawValue)
65+
Self(rawValue: 1 << Options.secondDay.rawValue)
6666
6767
static let priority: Self =
68-
Self (rawValue: 1 << Options.priority.rawValue)
68+
Self(rawValue: 1 << Options.priority.rawValue)
6969
7070
static let standard: Self =
71-
Self (rawValue: 1 << Options.standard.rawValue)
71+
Self(rawValue: 1 << Options.standard.rawValue)
7272
}
7373
7474
extension ShippingOptions: OptionSet {
@@ -110,10 +110,10 @@ final class OptionSetMacroTests: XCTestCase {
110110
}
111111
112112
public static let nextDay: Self =
113-
Self (rawValue: 1 << Options.nextDay.rawValue)
113+
Self(rawValue: 1 << Options.nextDay.rawValue)
114114
115115
public static let standard: Self =
116-
Self (rawValue: 1 << Options.standard.rawValue)
116+
Self(rawValue: 1 << Options.standard.rawValue)
117117
}
118118
""",
119119
macros: macros,

Examples/Tests/MacroExamples/Implementation/Member/CustomCodableTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ final class CustomCodableTests: XCTestCase {
3333
let age: Int
3434
3535
enum CodingKeys: String, CodingKey {
36-
case name
37-
case age
38-
}
36+
case name
37+
case age
38+
}
3939
}
4040
""",
4141
macros: macros,
@@ -62,9 +62,9 @@ final class CustomCodableTests: XCTestCase {
6262
func randomFunction() {}
6363
6464
enum CodingKeys: String, CodingKey {
65-
case name
66-
case age = "user_age"
67-
}
65+
case name
66+
case age = "user_age"
67+
}
6868
}
6969
""",
7070
macros: macros,

Examples/Tests/MacroExamples/Implementation/Member/MetaEnumMacroTests.swift

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,23 @@ final class MetaEnumMacroTests: XCTestCase {
3636
case null
3737
3838
enum Meta {
39-
case integer
40-
case text
41-
case boolean
42-
case null
43-
44-
init(_ __macro_local_6parentfMu_: Cell) {
45-
switch __macro_local_6parentfMu_ {
46-
case .integer:
47-
self = .integer
48-
case .text:
49-
self = .text
50-
case .boolean:
51-
self = .boolean
52-
case .null:
53-
self = .null
54-
}
55-
}
39+
case integer
40+
case text
41+
case boolean
42+
case null
43+
init(_ __macro_local_6parentfMu_: Cell) {
44+
switch __macro_local_6parentfMu_ {
45+
case .integer:
46+
self = .integer
47+
case .text:
48+
self = .text
49+
case .boolean:
50+
self = .boolean
51+
case .null:
52+
self = .null
53+
}
5654
}
55+
}
5756
}
5857
""",
5958
macros: macros,
@@ -77,21 +76,20 @@ final class MetaEnumMacroTests: XCTestCase {
7776
case boolean(Bool)
7877
7978
public enum Meta {
80-
case integer
81-
case text
82-
case boolean
83-
84-
public init(_ __macro_local_6parentfMu_: Cell) {
85-
switch __macro_local_6parentfMu_ {
86-
case .integer:
87-
self = .integer
88-
case .text:
89-
self = .text
90-
case .boolean:
91-
self = .boolean
92-
}
93-
}
79+
case integer
80+
case text
81+
case boolean
82+
public init(_ __macro_local_6parentfMu_: Cell) {
83+
switch __macro_local_6parentfMu_ {
84+
case .integer:
85+
self = .integer
86+
case .text:
87+
self = .text
88+
case .boolean:
89+
self = .boolean
90+
}
9491
}
92+
}
9593
}
9694
""",
9795
macros: macros,

Examples/Tests/MacroExamples/Implementation/Peer/AddAsyncMacroTests.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ final class AddAsyncMacroTests: XCTestCase {
3636
c(a: a, for: b, value) { returnValue in
3737
3838
switch returnValue {
39-
case .success(let value):
40-
continuation.resume(returning: value)
41-
case .failure(let error):
42-
continuation.resume(throwing: error)
43-
}
44-
39+
case .success(let value):
40+
continuation.resume(returning: value)
41+
case .failure(let error):
42+
continuation.resume(throwing: error)
43+
}
4544
}
4645
}
4746
}
@@ -68,8 +67,7 @@ final class AddAsyncMacroTests: XCTestCase {
6867
await withCheckedContinuation { continuation in
6968
d(a: a, for: b, value) { returnValue in
7069
71-
continuation.resume(returning: returnValue)
72-
70+
continuation.resume(returning: returnValue)
7371
}
7472
}
7573
}

0 commit comments

Comments
 (0)