Skip to content

Commit d37896a

Browse files
author
Golovin Dmitrii Mikhaylovich
committed
swiftformat
1 parent 2922d41 commit d37896a

22 files changed

+110
-120
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
),
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/swiftlang/swift-syntax.git", "600.0.0" ..< "601.0.1"),
20+
.package(url: "https://github.com/swiftlang/swift-syntax.git", "600.0.0"..<"601.0.1"),
2121
],
2222
targets: [
2323
.macro(

Sources/OzonTestingMacros/AnyMockableMacro/AnyMockableMacro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public struct AnyMockableMacro: MemberMacro {
9999
///
100100
private static func makeModifiersForMockClass(_ declAccessModifier: DeclModifierSyntax) -> DeclModifierListSyntax {
101101
if declAccessModifier.isOpen {
102-
return .init(arrayLiteral: declAccessModifier)
102+
.init(arrayLiteral: declAccessModifier)
103103
} else {
104-
return .init(arrayLiteral: declAccessModifier, .init(name: .keyword(.final)))
104+
.init(arrayLiteral: declAccessModifier, .init(name: .keyword(.final)))
105105
}
106106
}
107107
}

Sources/OzonTestingMacros/ArbitraryMacro/ArbitraryMacro.swift

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ public struct ArbitraryMacro: PeerMacro {
5959

6060
partialResult.append(.init(name: name, type: type, isIgnored: variable.isIgnored, isNilable: variable.isNilable))
6161
}
62-
let arbitraryMethod: FunctionDeclSyntax
63-
64-
switch arbitraryType {
62+
let arbitraryMethod: FunctionDeclSyntax = switch arbitraryType {
6563
case .mock:
66-
arbitraryMethod = makeArbitraryMethodForMock(
64+
makeArbitraryMethodForMock(
6765
accessModifier: accessModifier,
6866
typeName: typeName,
6967
parameters: parameters,
7068
arbitraryConfig: arbitraryConfig,
7169
declMembers: declGroup.memberBlock.members
7270
)
7371
case .model:
74-
arbitraryMethod = makeArbitraryMethodForModel(
72+
makeArbitraryMethodForModel(
7573
accessModifier: accessModifier,
7674
typeName: typeName,
7775
parameters: parameters,
@@ -148,29 +146,29 @@ public struct ArbitraryMacro: PeerMacro {
148146
///
149147
static func getVariableType(_ type: TypeSyntax) -> VariableType {
150148
if let optionalType = type.as(OptionalTypeSyntax.self), !optionalType.wrappedType.is(MemberTypeSyntax.self) {
151-
return .optional
149+
.optional
152150
} else if let optionalType = type.as(OptionalTypeSyntax.self), optionalType.wrappedType.is(MemberTypeSyntax.self) {
153-
return .nested(cleanType: optionalType.wrappedType)
151+
.nested(cleanType: optionalType.wrappedType)
154152
} else if isSwiftOrFoundationType(type) {
155-
return .foundation
153+
.foundation
156154
} else if type.is(ArrayTypeSyntax.self) || type.as(IdentifierTypeSyntax.self)?.name.text == String.array {
157-
return .array
155+
.array
158156
} else if let forceUnwrappedType = type.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) {
159-
return getVariableType(forceUnwrappedType.wrappedType)
157+
getVariableType(forceUnwrappedType.wrappedType)
160158
} else if let functionType = type.findSyntaxInTree(FunctionTypeSyntax.self) {
161-
return .closure(cleanType: functionType)
159+
.closure(cleanType: functionType)
162160
} else if type.is(TupleTypeSyntax.self) {
163-
return .tuple
161+
.tuple
164162
} else if type.is(DictionaryTypeSyntax.self) || type.as(IdentifierTypeSyntax.self)?.name.text == String.dictionary {
165-
return .dictionary
163+
.dictionary
166164
} else if let type = type.as(IdentifierTypeSyntax.self)?.name.text, type == String.set {
167-
return .set
165+
.set
168166
} else if type.is(MemberTypeSyntax.self) {
169-
return .nested(cleanType: type)
167+
.nested(cleanType: type)
170168
} else if let attributedType = type.as(AttributedTypeSyntax.self) {
171-
return getVariableType(attributedType.baseType)
169+
getVariableType(attributedType.baseType)
172170
} else {
173-
return .custom
171+
.custom
174172
}
175173
}
176174

@@ -216,19 +214,19 @@ public struct ArbitraryMacro: PeerMacro {
216214
private static func getTypeNameFromDecl(_ decl: DeclGroupSyntax) -> TokenSyntax? {
217215
switch decl.kind {
218216
case .classDecl:
219-
return decl.as(ClassDeclSyntax.self)?.name
217+
decl.as(ClassDeclSyntax.self)?.name
220218
case .structDecl:
221-
return decl.as(StructDeclSyntax.self)?.name
219+
decl.as(StructDeclSyntax.self)?.name
222220
case .extensionDecl:
223-
return decl.as(ExtensionDeclSyntax.self)?.extendedType.as(IdentifierTypeSyntax.self)?.name
221+
decl.as(ExtensionDeclSyntax.self)?.extendedType.as(IdentifierTypeSyntax.self)?.name
224222
case .actorDecl:
225-
return decl.as(ActorDeclSyntax.self)?.name
223+
decl.as(ActorDeclSyntax.self)?.name
226224
case .enumDecl:
227-
return decl.as(EnumDeclSyntax.self)?.name
225+
decl.as(EnumDeclSyntax.self)?.name
228226
case .protocolDecl:
229-
return decl.as(ProtocolDeclSyntax.self)?.name
227+
decl.as(ProtocolDeclSyntax.self)?.name
230228
default:
231-
return nil
229+
nil
232230
}
233231
}
234232
}

Sources/OzonTestingMacros/ArbitraryMacro/ArbitraryMacroError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ enum ArbitraryMacroError: CustomStringConvertible, Error {
1313
var description: String {
1414
switch self {
1515
case .unsupportedType:
16-
return "@Arbitrary macro is attached to an unsupported declaration"
16+
"@Arbitrary macro is attached to an unsupported declaration"
1717
case .wrongArbitraryType:
18-
return "ArbitraryType can only be static or dynamic"
18+
"ArbitraryType can only be static or dynamic"
1919
}
2020
}
2121
}

Sources/OzonTestingMacros/ArbitraryMacro/ArbitraryProtocolFlow.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension ArbitraryMacro {
4545
),
4646
returnClause: .init(type: IdentifierTypeSyntax(name: typeName))
4747
),
48-
body: makeArbitraryMethodBody(typeName: typeName, parameters: parameters.map { $0.name })
48+
body: makeArbitraryMethodBody(typeName: typeName, parameters: parameters.map(\.name))
4949
)
5050
}
5151

@@ -158,7 +158,7 @@ extension ArbitraryMacro {
158158
period: .periodToken(),
159159
declName: DeclReferenceExprSyntax(baseName: .identifier(arbitraryIdentifier))
160160
)
161-
case let .nested(cleanType):
161+
case .nested(let cleanType):
162162
let typeName: String
163163
let type = cleanType.as(MemberTypeSyntax.self)
164164
let baseTypeName = type?.baseType.as(IdentifierTypeSyntax.self)?.name.text
@@ -180,7 +180,7 @@ extension ArbitraryMacro {
180180
arguments: .init([]),
181181
rightParen: .rightParenToken()
182182
)
183-
case let .closure(functionType):
183+
case .closure(let functionType):
184184
var wildcards: ClosureShorthandParameterListSyntax = .init()
185185

186186
functionType.parameters.forEach { element in
@@ -441,7 +441,7 @@ extension ArbitraryMacro {
441441
///
442442
private static func getInnerTypesFromMembers(_ members: MemberBlockItemListSyntax) -> [String] {
443443
members
444-
.filter { $0.decl.isTypeSyntax }
444+
.filter(\.decl.isTypeSyntax)
445445
.compactMap { member in
446446
let decl = member.decl
447447

Sources/OzonTestingMacros/ArbitraryMacro/MemberArbitraryMacro.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ extension ArbitraryMacro: MemberMacro {
5656
let initParameterList = variables.enumerated().reduce(into: FunctionParameterListSyntax()) { partialResult, item in
5757
let variable = item.element
5858

59-
let parameter: FunctionParameterSyntax
60-
61-
if variable.1.is(FunctionTypeSyntax.self) {
62-
parameter = FunctionParameterSyntax(
59+
let parameter = if variable.1.is(FunctionTypeSyntax.self) {
60+
FunctionParameterSyntax(
6361
firstName: variable.0,
6462
type: AttributedTypeSyntax(
6563
specifiers: .init([]),
@@ -74,7 +72,7 @@ extension ArbitraryMacro: MemberMacro {
7472
trailingComma: item.offset == variables.count - 1 ? nil : .commaToken()
7573
)
7674
} else {
77-
parameter = FunctionParameterSyntax(
75+
FunctionParameterSyntax(
7876
firstName: variable.0,
7977
type: variable.1,
8078
trailingComma: item.offset == variables.count - 1 ? nil : .commaToken()
@@ -93,7 +91,7 @@ extension ArbitraryMacro: MemberMacro {
9391
return .init(
9492
modifiers: accessModifiers,
9593
signature: initSignature,
96-
body: makeInitBody(variables: variables.map { $0.0 })
94+
body: makeInitBody(variables: variables.map(\.0))
9795
)
9896
}
9997

Sources/OzonTestingMacros/AutoEquatableMacro.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public struct AutoEquatableMacro: ExtensionMacro {
133133

134134
return EnumCase(title: title, parameters: parameters)
135135
}
136-
.compactMap { $0 }
136+
.compactMap(\.self)
137137
}
138138

139139
/// Generates the name of the parameter based on the associative type of the case parameter.
@@ -178,7 +178,7 @@ public struct AutoEquatableMacro: ExtensionMacro {
178178
let codeBlock: CodeBlockSyntax
179179

180180
switch bodyContentType {
181-
case let .enum(enumCases, variables):
181+
case .enum(let enumCases, let variables):
182182
let switchExpr = makeSwitchExpr(enumCases: enumCases, enumHasVariables: !variables.isEmpty)
183183
let item = ExpressionStmtSyntax(expression: switchExpr)
184184
let codeBlockItem = CodeBlockItemSyntax.Item(item)
@@ -192,7 +192,7 @@ public struct AutoEquatableMacro: ExtensionMacro {
192192

193193
stmnts.append(.init(item: codeBlockItem))
194194
codeBlock = CodeBlockSyntax(statements: stmnts)
195-
case let .other(variables):
195+
case .other(let variables):
196196
codeBlock = makeFuncBody(variables: variables)
197197
}
198198

@@ -294,11 +294,10 @@ public struct AutoEquatableMacro: ExtensionMacro {
294294
/// - Returns: the syntax of the case for the `Switch` expression.
295295
///
296296
private static func makeEnumCase(_ caseModel: EnumCase, enumHasVariables: Bool) -> SwitchCaseSyntax {
297-
let tupleExpr: TupleExprSyntax
298-
if caseModel.parameters.isEmpty {
299-
tupleExpr = makeEnumCaseTupleExprWithoutParameter(caseModel)
297+
let tupleExpr: TupleExprSyntax = if caseModel.parameters.isEmpty {
298+
makeEnumCaseTupleExprWithoutParameter(caseModel)
300299
} else {
301-
tupleExpr = makeEnumCaseTupleExprWithParameters(caseModel)
300+
makeEnumCaseTupleExprWithParameters(caseModel)
302301
}
303302

304303
let switchCaseItem = SwitchCaseItemSyntax(
@@ -308,19 +307,18 @@ public struct AutoEquatableMacro: ExtensionMacro {
308307
caseItems: .init([switchCaseItem])
309308
)
310309

311-
let returnStmt: ReturnStmtSyntax
312-
if caseModel.parameters.isEmpty, !enumHasVariables {
313-
returnStmt = ReturnStmtSyntax(
310+
let returnStmt: ReturnStmtSyntax = if caseModel.parameters.isEmpty, !enumHasVariables {
311+
ReturnStmtSyntax(
314312
returnKeyword: .keyword(.return),
315313
expression: BooleanLiteralExprSyntax(literal: .keyword(.true))
316314
)
317315
} else if enumHasVariables, caseModel.parameters.isEmpty {
318-
returnStmt = ReturnStmtSyntax(
316+
ReturnStmtSyntax(
319317
returnKeyword: .keyword(.return),
320318
expression: DeclReferenceExprSyntax(baseName: .identifier(.otherVariablesCheck))
321319
)
322320
} else {
323-
returnStmt = makeReturnStmt(parameters: caseModel.parameters, enumHasVariables: enumHasVariables)
321+
makeReturnStmt(parameters: caseModel.parameters, enumHasVariables: enumHasVariables)
324322
}
325323

326324
let codeBlockItem = CodeBlockItemSyntax.Item(returnStmt)

Sources/OzonTestingMacros/Builders/ClearFunctionBlockBuilder.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ final class ClearMethodBuilder {
2525

2626
var propertyName: String {
2727
switch self {
28-
case let .collection(propertyName),
29-
let .nilable(propertyName):
30-
return propertyName
28+
case .collection(let propertyName),
29+
.nilable(let propertyName):
30+
propertyName
3131
}
3232
}
3333
}
@@ -91,15 +91,13 @@ final class ClearMethodBuilder {
9191
}
9292

9393
let modifiers = parameters.reduce(into: DeclModifierListSyntax()) { partialResult, parameter in
94-
let modifier: DeclModifierSyntax
95-
96-
switch parameter {
94+
let modifier: DeclModifierSyntax = switch parameter {
9795
case .open:
98-
modifier = .init(name: .keyword(.open))
96+
.init(name: .keyword(.open))
9997
case .overriding:
100-
modifier = .init(name: .keyword(.override))
98+
.init(name: .keyword(.override))
10199
case .public:
102-
modifier = .init(name: .keyword(.public))
100+
.init(name: .keyword(.public))
103101
}
104102

105103
partialResult.append(modifier)
@@ -146,13 +144,11 @@ final class ClearMethodBuilder {
146144
}
147145
}
148146

149-
let rightOperand: ExprSyntaxProtocol
150-
151-
switch item.element {
147+
let rightOperand: ExprSyntaxProtocol = switch item.element {
152148
case .nilable:
153-
rightOperand = NilLiteralExprSyntax()
149+
NilLiteralExprSyntax()
154150
case .collection:
155-
rightOperand = ArrayExprSyntax(elements: .init([]))
151+
ArrayExprSyntax(elements: .init([]))
156152
}
157153

158154
let expr = InfixOperatorExprSyntax(

Sources/OzonTestingMacros/Builders/DeinitBlockBuilder.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ enum DeinitBlockBuilder {
5656

5757
guard !clearMethodNames.isEmpty else { return [] }
5858

59-
let functionCalls: [ExprSyntaxProtocol]
60-
61-
switch dataStructure {
59+
let functionCalls: [ExprSyntaxProtocol] = switch dataStructure {
6260
case .actor:
63-
functionCalls = makeFunctionCallsForActor(clearMethodNames: clearMethodNames)
61+
makeFunctionCallsForActor(clearMethodNames: clearMethodNames)
6462
case .finalClass,
6563
.nonFinalClass:
66-
functionCalls = makeFunctionCallsForClass(clearMethodNames: clearMethodNames)
64+
makeFunctionCallsForClass(clearMethodNames: clearMethodNames)
6765
}
6866

6967
let codeBlockItemList: CodeBlockItemListSyntax = functionCalls
@@ -72,12 +70,10 @@ enum DeinitBlockBuilder {
7270
partialResult.append(.init(item: item))
7371
}
7472

75-
let deinitDecl: DeinitializerDeclSyntax
76-
77-
if dataStructure == .actor {
78-
deinitDecl = DeinitializerDeclSyntax(body: .init(statements: makeTaskCall(body: codeBlockItemList)))
73+
let deinitDecl = if dataStructure == .actor {
74+
DeinitializerDeclSyntax(body: .init(statements: makeTaskCall(body: codeBlockItemList)))
7975
} else {
80-
deinitDecl = DeinitializerDeclSyntax(body: .init(statements: codeBlockItemList))
76+
DeinitializerDeclSyntax(body: .init(statements: codeBlockItemList))
8177
}
8278

8379
result.append(.init(decl: deinitDecl))

0 commit comments

Comments
 (0)