Skip to content

Commit fe65260

Browse files
committed
more lint fixes
1 parent 555f88d commit fe65260

File tree

12 files changed

+105
-32
lines changed

12 files changed

+105
-32
lines changed

Sources/SyntaxKit/Assignment.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public struct Assignment: CodeBlock {
7171
elements: ExprListSyntax([
7272
left,
7373
ExprSyntax(
74-
AssignmentExprSyntax(equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space))),
74+
AssignmentExprSyntax(equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space))
75+
),
7576
right,
7677
])
7778
)

Sources/SyntaxKit/Default.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public struct Default: CodeBlock {
5050
item = CodeBlockItemSyntax(item: .stmt(stmt))
5151
}
5252
return item?.with(\.trailingTrivia, .newline)
53-
})
53+
}
54+
)
5455
let label = SwitchDefaultLabelSyntax(
5556
defaultKeyword: .keyword(.default),
5657
colon: .colonToken(trailingTrivia: .newline)

Sources/SyntaxKit/DictionaryValue.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extension Literal: DictionaryValue {
4545
// MARK: - CodeBlock Conformance
4646

4747
extension CodeBlock where Self: DictionaryValue {
48+
/// Converts this code block to an expression syntax.
49+
/// If the code block is already an expression, returns it directly.
50+
/// If it's a token, wraps it in a declaration reference expression.
51+
/// Otherwise, throws a fatal error.
4852
public var exprSyntax: ExprSyntax {
4953
if let expr = self.syntax.as(ExprSyntax.self) {
5054
return expr

Sources/SyntaxKit/Do.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public struct Do: CodeBlock {
6262
item = CodeBlockItemSyntax(item: .stmt(stmt))
6363
}
6464
return item?.with(\.trailingTrivia, .newline)
65-
}),
65+
}
66+
),
6667
rightBrace: .rightBraceToken(leadingTrivia: .newline, trailingTrivia: .space)
6768
)
6869

Sources/SyntaxKit/Infix.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,47 @@ public struct Infix: CodeBlock {
7171

7272
// MARK: - Operator Overloads for Infix Expressions
7373

74+
/// Creates a greater-than comparison expression.
75+
/// - Parameters:
76+
/// - lhs: The left-hand side expression.
77+
/// - rhs: The right-hand side expression.
78+
/// - Returns: An infix expression representing `lhs > rhs`.
7479
public func > (lhs: CodeBlock, rhs: CodeBlock) -> Infix {
7580
Infix(">") {
7681
lhs
7782
rhs
7883
}
7984
}
8085

86+
/// Creates a less-than comparison expression.
87+
/// - Parameters:
88+
/// - lhs: The left-hand side expression.
89+
/// - rhs: The right-hand side expression.
90+
/// - Returns: An infix expression representing `lhs < rhs`.
8191
public func < (lhs: CodeBlock, rhs: CodeBlock) -> Infix {
8292
Infix("<") {
8393
lhs
8494
rhs
8595
}
8696
}
8797

98+
/// Creates an equality comparison expression.
99+
/// - Parameters:
100+
/// - lhs: The left-hand side expression.
101+
/// - rhs: The right-hand side expression.
102+
/// - Returns: An infix expression representing `lhs == rhs`.
88103
public func == (lhs: CodeBlock, rhs: CodeBlock) -> Infix {
89104
Infix("==") {
90105
lhs
91106
rhs
92107
}
93108
}
94109

110+
/// Creates an inequality comparison expression.
111+
/// - Parameters:
112+
/// - lhs: The left-hand side expression.
113+
/// - rhs: The right-hand side expression.
114+
/// - Returns: An infix expression representing `lhs != rhs`.
95115
public func != (lhs: CodeBlock, rhs: CodeBlock) -> Infix {
96116
Infix("!=") {
97117
lhs

Sources/SyntaxKit/VariableDecl.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public struct VariableDecl: CodeBlock {
5757
openingQuote: .stringQuoteToken(),
5858
segments: StringLiteralSegmentListSyntax([
5959
.stringSegment(
60-
StringSegmentSyntax(content: .stringSegment(String(value.dropFirst().dropLast()))))
60+
StringSegmentSyntax(content: .stringSegment(String(value.dropFirst().dropLast())))
61+
)
6162
]),
6263
closingQuote: .stringQuoteToken()
6364
)
@@ -69,7 +70,8 @@ public struct VariableDecl: CodeBlock {
6970
openingQuote: .stringQuoteToken(),
7071
segments: StringLiteralSegmentListSyntax([
7172
.stringSegment(
72-
StringSegmentSyntax(content: .stringSegment(value)))
73+
StringSegmentSyntax(content: .stringSegment(value))
74+
)
7375
]),
7476
closingQuote: .stringQuoteToken()
7577
)

Tests/SyntaxKitTests/Integration/ConditionalsExampleTests.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,15 @@ import Testing
200200
SwitchCase(Tuple.pattern([(-2...2), (-2...2)])) {
201201
Call("print") {
202202
ParameterExp(
203-
name: "", value: "\"(\\(somePoint.0), \\(somePoint.1)) is inside the box\"")
203+
name: "", value: "\"(\\(somePoint.0), \\(somePoint.1)) is inside the box\""
204+
)
204205
}
205206
}
206207
Default {
207208
Call("print") {
208209
ParameterExp(
209-
name: "", value: "\"(\\(somePoint.0), \\(somePoint.1)) is outside of the box\"")
210+
name: "", value: "\"(\\(somePoint.0), \\(somePoint.1)) is outside of the box\""
211+
)
210212
}
211213
}
212214
}
@@ -220,17 +222,23 @@ import Testing
220222
Switch("anotherPoint") {
221223
SwitchCase(Tuple.pattern([Pattern.let("x"), 0])) {
222224
Call("print") {
223-
ParameterExp(name: "", value: "\"on the x-axis with an x value of \\(x)\"")
225+
ParameterExp(
226+
name: "", value: "\"on the x-axis with an x value of \\(x)\""
227+
)
224228
}
225229
}
226230
SwitchCase(Tuple.pattern([0, Pattern.let("y")])) {
227231
Call("print") {
228-
ParameterExp(name: "", value: "\"on the y-axis with a y value of \\(y)\"")
232+
ParameterExp(
233+
name: "", value: "\"on the y-axis with a y value of \\(y)\""
234+
)
229235
}
230236
}
231237
SwitchCase(Tuple.pattern([Pattern.let("x"), Pattern.let("y")])) {
232238
Call("print") {
233-
ParameterExp(name: "", value: "\"somewhere else at (\\(x), \\(y))\"")
239+
ParameterExp(
240+
name: "", value: "\"somewhere else at (\\(x), \\(y))\""
241+
)
234242
}
235243
}
236244
}
@@ -269,7 +277,8 @@ import Testing
269277
value: Infix("+") {
270278
VariableExp("finalSquare")
271279
Literal.integer(1)
272-
})
280+
}
281+
)
273282
}
274283
}
275284

Tests/SyntaxKitTests/Integration/ForLoopsExampleTests.swift

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import Testing
1111
let program = Group {
1212
// MARK: - Basic For-in Loop
1313
Variable(
14-
.let, name: "names",
14+
.let,
15+
name: "names",
1516
equals: Literal.array([
16-
Literal.string("Alice"), Literal.string("Bob"), Literal.string("Charlie"),
17+
Literal.string("Alice"),
18+
Literal.string("Bob"),
19+
Literal.string("Charlie"),
1720
])
1821
)
1922
.comment {
@@ -22,12 +25,14 @@ import Testing
2225
}
2326

2427
For(
25-
VariableExp("name"), in: VariableExp("names"),
28+
VariableExp("name"),
29+
in: VariableExp("names"),
2630
then: {
2731
Call("print") {
2832
ParameterExp(unlabeled: "\"Hello, \\(name)!\"")
2933
}
30-
})
34+
}
35+
)
3136

3237
// MARK: - For-in with Enumerated
3338
Call("print") {
@@ -38,13 +43,17 @@ import Testing
3843
Line("For-in loop with enumerated() to get index and value")
3944
}
4045
For(
41-
Tuple.patternCodeBlock([VariableExp("index"), VariableExp("name")]),
46+
Tuple.patternCodeBlock([
47+
VariableExp("index"),
48+
VariableExp("name"),
49+
]),
4250
in: VariableExp("names").call("enumerated"),
4351
then: {
4452
Call("print") {
4553
ParameterExp(unlabeled: "\"Index: \\(index), Name: \\(name)\"")
4654
}
47-
})
55+
}
56+
)
4857

4958
// MARK: - For-in with Where Clause
5059
Call("print") {
@@ -55,15 +64,25 @@ import Testing
5564
Line("For-in loop with where clause")
5665
}
5766
Variable(
58-
.let, name: "numbers",
67+
.let,
68+
name: "numbers",
5969
equals: Literal.array([
60-
Literal.integer(1), Literal.integer(2), Literal.integer(3), Literal.integer(4),
61-
Literal.integer(5), Literal.integer(6), Literal.integer(7), Literal.integer(8),
62-
Literal.integer(9), Literal.integer(10),
63-
]))
70+
Literal.integer(1),
71+
Literal.integer(2),
72+
Literal.integer(3),
73+
Literal.integer(4),
74+
Literal.integer(5),
75+
Literal.integer(6),
76+
Literal.integer(7),
77+
Literal.integer(8),
78+
Literal.integer(9),
79+
Literal.integer(10),
80+
])
81+
)
6482

6583
For(
66-
VariableExp("number"), in: VariableExp("numbers"),
84+
VariableExp("number"),
85+
in: VariableExp("numbers"),
6786
where: {
6887
Infix("==") {
6988
Infix("%") {
@@ -89,21 +108,27 @@ import Testing
89108
Line("For-in loop over dictionary")
90109
}
91110
Variable(
92-
.let, name: "scores",
111+
.let,
112+
name: "scores",
93113
equals: Literal.dictionary([
94114
(Literal.string("Alice"), Literal.integer(95)),
95115
(Literal.string("Bob"), Literal.integer(87)),
96116
(Literal.string("Charlie"), Literal.integer(92)),
97-
]))
117+
])
118+
)
98119

99120
For(
100-
Tuple.patternCodeBlock([VariableExp("name"), VariableExp("score")]),
121+
Tuple.patternCodeBlock([
122+
VariableExp("name"),
123+
VariableExp("score"),
124+
]),
101125
in: VariableExp("scores"),
102126
then: {
103127
Call("print") {
104128
ParameterExp(unlabeled: "\"\\(name): \\(score)\"")
105129
}
106-
})
130+
}
131+
)
107132
}
108133

109134
// Generate Swift from DSL

Tests/SyntaxKitTests/Unit/CatchComplexTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import Testing
2626

2727
let generated = doCatch.generateCode()
2828
let expected =
29-
"do { try someFunction(param: \"test\") } catch .requestFailed(let statusCode, let message) { logAPIError(statusCode: statusCode, message: message) }"
29+
"do { try someFunction(param: \"test\") } catch .requestFailed(let statusCode, let message) { "
30+
+ "logAPIError(statusCode: statusCode, message: message) }"
3031

3132
#expect(generated.normalize() == expected.normalize())
3233
}

Tests/SyntaxKitTests/Unit/EdgeCaseTestsTypes.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ internal struct EdgeCaseTestsTypes {
1212
let generated = typeAlias.generateCode()
1313
#expect(
1414
generated.normalize().contains(
15-
"typealias ComplexType = Array<Dictionary<String, Optional<Int>>>".normalize()))
15+
"typealias ComplexType = Array<Dictionary<String, Optional<Int>>>".normalize()
16+
)
17+
)
1618
}
1719

1820
@Test("TypeAlias with multiple generic parameters")

0 commit comments

Comments
 (0)