Skip to content

Commit cf967a2

Browse files
stephencelisgithub-actions[bot]
authored andcommitted
Run swift-format
1 parent f75f938 commit cf967a2

File tree

5 files changed

+76
-69
lines changed

5 files changed

+76
-69
lines changed

Examples/Integration/Integration/Legacy/LegacyPresentationTestCase.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import SwiftUI
33
import SwiftUINavigation
44

5-
fileprivate enum PresentationTestCase {
5+
private enum PresentationTestCase {
66
@Reducer
77
struct Feature {
88
struct State: Equatable {
@@ -86,8 +86,8 @@ fileprivate enum PresentationTestCase {
8686
return .none
8787

8888
case .destination(.presented(.fullScreenCover(.parentSendDismissActionButtonTapped))),
89-
.destination(.presented(.sheet(.parentSendDismissActionButtonTapped))),
90-
.destination(.presented(.popover(.parentSendDismissActionButtonTapped))):
89+
.destination(.presented(.sheet(.parentSendDismissActionButtonTapped))),
90+
.destination(.presented(.popover(.parentSendDismissActionButtonTapped))):
9191
return .send(.destination(.dismiss))
9292

9393
case let .destination(.presented(.alert(alertAction))):
@@ -141,9 +141,9 @@ fileprivate enum PresentationTestCase {
141141
}
142142

143143
case .destination(.presented(.fullScreenCover(.dismissAndAlert))),
144-
.destination(.presented(.popover(.dismissAndAlert))),
145-
.destination(.presented(.navigationDestination(.dismissAndAlert))),
146-
.destination(.presented(.sheet(.dismissAndAlert))):
144+
.destination(.presented(.popover(.dismissAndAlert))),
145+
.destination(.presented(.navigationDestination(.dismissAndAlert))),
146+
.destination(.presented(.sheet(.dismissAndAlert))):
147147
state.destination = .alert(
148148
AlertState {
149149
TextState("Hello!")

Examples/Integration/Integration/Legacy/PresentationItemTestCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ComposableArchitecture
22
import SwiftUI
33

4-
fileprivate enum PresentationItemTestCase {
4+
private enum PresentationItemTestCase {
55
@Reducer
66
struct Feature {
77
@Reducer

Sources/ComposableArchitecture/CaseReducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///
33
/// You should not conform to this protocol directly. Instead, the ``Reducer()`` macro will add a
44
/// conformance to enums.
5-
public protocol CaseReducer<State,Action>: Reducer
5+
public protocol CaseReducer<State, Action>: Reducer
66
where State: CaseReducerState, Body: Reducer, Body.State == State, Body.Action == Action {
77
associatedtype State = State
88
associatedtype Action = Action

Sources/ComposableArchitecture/Macros.swift

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
member,
1010
names:
1111
named(State),
12-
named(Action),
13-
named(init),
14-
named(body),
15-
named(CaseScope),
16-
named(scope)
12+
named(Action),
13+
named(init),
14+
named(body),
15+
named(CaseScope),
16+
named(scope)
1717
)
1818
@attached(memberAttribute)
1919
@attached(extension, conformances: Reducer, CaseReducer)
@@ -32,11 +32,11 @@
3232
member,
3333
names:
3434
named(State),
35-
named(Action),
36-
named(init),
37-
named(body),
38-
named(CaseScope),
39-
named(scope)
35+
named(Action),
36+
named(init),
37+
named(body),
38+
named(CaseScope),
39+
named(scope)
4040
)
4141
@attached(memberAttribute)
4242
@attached(extension, conformances: Reducer, CaseReducer)
@@ -51,31 +51,31 @@
5151
///
5252
/// See <doc:Reducers#Synthesizing-protocol-conformances-on-State-and-Action> for more
5353
/// information.
54-
@_documentation(visibility: public)
54+
@_documentation(visibility:public)
5555
public struct _SynthesizedConformance {}
5656
#else
5757
public struct _SynthesizedConformance {}
5858
#endif
59-
extension _SynthesizedConformance {
60-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Codable`
61-
/// protocol.
62-
public static let codable = Self()
63-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Decodable`
64-
/// protocol.
65-
public static let decodable = Self()
66-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Encodable`
67-
/// protocol.
68-
public static let encodable = Self()
69-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Equatable`
70-
/// protocol.
71-
public static let equatable = Self()
72-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Hashable`
73-
/// protocol.
74-
public static let hashable = Self()
75-
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Sendable`
76-
/// protocol.
77-
public static let sendable = Self()
78-
}
59+
extension _SynthesizedConformance {
60+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Codable`
61+
/// protocol.
62+
public static let codable = Self()
63+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Decodable`
64+
/// protocol.
65+
public static let decodable = Self()
66+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Encodable`
67+
/// protocol.
68+
public static let encodable = Self()
69+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Equatable`
70+
/// protocol.
71+
public static let equatable = Self()
72+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Hashable`
73+
/// protocol.
74+
public static let hashable = Self()
75+
/// Extends the `State` or `Action` types that ``Reducer()`` creates with the `Sendable`
76+
/// protocol.
77+
public static let sendable = Self()
78+
}
7979

8080
/// Marks the case of an enum reducer as holding onto "ephemeral" state.
8181
///
@@ -201,4 +201,3 @@
201201
module: "ComposableArchitectureMacros", type: "ViewActionMacro"
202202
) where R.Action: ViewAction
203203
#endif
204-

Sources/ComposableArchitectureMacros/ReducerMacro.swift

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ extension ReducerMacro: ExtensionMacro {
2525
{
2626
return []
2727
}
28-
let proto = declaration.isEnum
28+
let proto =
29+
declaration.isEnum
2930
? "ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer"
3031
: "ComposableArchitecture.Reducer"
3132
let ext: DeclSyntax =
@@ -132,7 +133,8 @@ extension ReducerMacro: MemberAttributeMacro {
132133
!attributeName.starts(with: "ComposableArchitecture.ReducerBuilder")
133134
else { return [] }
134135
}
135-
let genericArguments = genericArguments.count == 1
136+
let genericArguments =
137+
genericArguments.count == 1
136138
? "\(genericArguments.description).State, \(genericArguments.description).Action"
137139
: "\(genericArguments)"
138140
return [
@@ -176,8 +178,8 @@ extension ReducerMacro: MemberAttributeMacro {
176178
}
177179
}
178180

179-
private extension IdentifierTypeSyntax {
180-
var isEphemeral: Bool {
181+
extension IdentifierTypeSyntax {
182+
fileprivate var isEphemeral: Bool {
181183
self.name.text == "AlertState" || self.name.text == "ConfirmationDialogState"
182184
}
183185
}
@@ -215,20 +217,23 @@ extension ReducerMacro: MemberMacro {
215217
}
216218
return true
217219
}
218-
let hasExplicitReducerBody = bindings.contains {
219-
guard $0.initializer == nil
220-
else { return true }
221-
guard let name = $0.typeAnnotation?.type.as(SomeOrAnyTypeSyntax.self)?.constraint
222-
.as(IdentifierTypeSyntax.self)?.name.text
223-
else {
224-
return false
225-
}
226-
return ["Reducer", "ReducerOf"].withQualified.contains(name)
227-
} || hasReduceMethod
228-
let hasBody = bindings.contains {
229-
$0.as(PatternBindingSyntax.self)?.pattern
230-
.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
231-
} || hasReduceMethod
220+
let hasExplicitReducerBody =
221+
bindings.contains {
222+
guard $0.initializer == nil
223+
else { return true }
224+
guard
225+
let name = $0.typeAnnotation?.type.as(SomeOrAnyTypeSyntax.self)?.constraint
226+
.as(IdentifierTypeSyntax.self)?.name.text
227+
else {
228+
return false
229+
}
230+
return ["Reducer", "ReducerOf"].withQualified.contains(name)
231+
} || hasReduceMethod
232+
let hasBody =
233+
bindings.contains {
234+
$0.as(PatternBindingSyntax.self)?.pattern
235+
.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
236+
} || hasReduceMethod
232237
var decls: [DeclSyntax] = []
233238
if let enumDecl = declaration.as(EnumDeclSyntax.self) {
234239
let enumCaseElements = enumDecl.memberBlock
@@ -257,7 +262,8 @@ extension ReducerMacro: MemberMacro {
257262
parameter.type.is(IdentifierTypeSyntax.self) || parameter.type.is(MemberTypeSyntax.self)
258263
{
259264
let type = parameter.type
260-
let stateCase = enumCaseElement.attribute == .ephemeral
265+
let stateCase =
266+
enumCaseElement.attribute == .ephemeral
261267
? element
262268
: element.suffixed("State")
263269
stateCaseDecls.append("case \(stateCase.trimmedDescription)")
@@ -311,7 +317,8 @@ extension ReducerMacro: MemberMacro {
311317
if case let .argumentList(arguments) = node.arguments,
312318
let startIndex = arguments.firstIndex(where: { $0.label?.text == "state" })
313319
{
314-
let endIndex = arguments.firstIndex(where: { $0.label?.text == "action" })
320+
let endIndex =
321+
arguments.firstIndex(where: { $0.label?.text == "action" })
315322
?? arguments.endIndex
316323
conformances.append(
317324
contentsOf: arguments[startIndex..<endIndex].compactMap {
@@ -400,7 +407,8 @@ extension ReducerMacro: MemberMacro {
400407
fixIt: .replace(
401408
message: MacroExpansionFixItMessage("Remove '(\(arguments))'"),
402409
oldNode: node,
403-
newNode: node
410+
newNode:
411+
node
404412
.with(\.leftParen, nil)
405413
.with(\.arguments, nil)
406414
.with(\.rightParen, nil)
@@ -487,8 +495,8 @@ private final class ReduceVisitor: SyntaxVisitor {
487495
}
488496
}
489497

490-
private extension EnumCaseDeclSyntax {
491-
var attribute: ReducerCase.Attribute? {
498+
extension EnumCaseDeclSyntax {
499+
fileprivate var attribute: ReducerCase.Attribute? {
492500
if self.isIgnored {
493501
return .ignored
494502
} else if self.isEphemeral {
@@ -498,12 +506,12 @@ private extension EnumCaseDeclSyntax {
498506
}
499507
}
500508

501-
var isIgnored: Bool {
509+
fileprivate var isIgnored: Bool {
502510
self.attributes.contains("ReducerCaseIgnored")
503511
|| self.elements.contains { $0.parameterClause?.parameters.count != 1 }
504512
}
505513

506-
var isEphemeral: Bool {
514+
fileprivate var isEphemeral: Bool {
507515
self.attributes.contains("ReducerCaseEphemeral")
508516
|| self.elements.contains {
509517
guard
@@ -517,8 +525,8 @@ private extension EnumCaseDeclSyntax {
517525
}
518526
}
519527

520-
private extension EnumCaseElementSyntax {
521-
func suffixed(_ suffix: TokenSyntax) -> Self {
528+
extension EnumCaseElementSyntax {
529+
fileprivate func suffixed(_ suffix: TokenSyntax) -> Self {
522530
var element = self
523531
if var parameterClause = element.parameterClause,
524532
let type = parameterClause.parameters.first?.type
@@ -531,8 +539,8 @@ private extension EnumCaseElementSyntax {
531539
}
532540
}
533541

534-
private extension AttributeListSyntax {
535-
func contains(_ name: TokenSyntax) -> Bool {
542+
extension AttributeListSyntax {
543+
fileprivate func contains(_ name: TokenSyntax) -> Bool {
536544
self.contains {
537545
guard
538546
case let .attribute(attribute) = $0,

0 commit comments

Comments
 (0)