Skip to content

Commit 53327ab

Browse files
authored
switch to swift format (#71)
* switched to swift-format * added swift-format-ignore for glitchy line * added format check
1 parent ee23a6c commit 53327ab

28 files changed

+475
-159
lines changed

.github/workflows/format.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Swift Format Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "**.swift"
8+
pull_request:
9+
branches: [main]
10+
workflow_dispatch:
11+
12+
jobs:
13+
linux:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 15
16+
strategy:
17+
matrix:
18+
image: ["swift:6.1"]
19+
20+
container:
21+
image: ${{ matrix.image }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Check Format
27+
run: swift format lint -prs .

.swift-format

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"version": 1,
3+
"indentation": {
4+
"spaces": 4
5+
},
6+
"tabWidth": 4,
7+
"fileScopedDeclarationPrivacy": {
8+
"accessLevel": "private"
9+
},
10+
"spacesAroundRangeFormationOperators": false,
11+
"indentConditionalCompilationBlocks": false,
12+
"indentSwitchCaseLabels": false,
13+
"lineBreakAroundMultilineExpressionChainComponents": false,
14+
"lineBreakBeforeControlFlowKeywords": false,
15+
"lineBreakBeforeEachArgument": true,
16+
"lineBreakBeforeEachGenericRequirement": true,
17+
"lineLength": 140,
18+
"maximumBlankLines": 1,
19+
"respectsExistingLineBreaks": true,
20+
"prioritizeKeepingFunctionOutputTogether": true,
21+
"multiElementCollectionTrailingCommas": true,
22+
"rules": {
23+
"AllPublicDeclarationsHaveDocumentation": false,
24+
"AlwaysUseLiteralForEmptyCollectionInit": false,
25+
"AlwaysUseLowerCamelCase": false,
26+
"AmbiguousTrailingClosureOverload": true,
27+
"BeginDocumentationCommentWithOneLineSummary": false,
28+
"DoNotUseSemicolons": false,
29+
"DontRepeatTypeInStaticProperties": true,
30+
"FileScopedDeclarationPrivacy": true,
31+
"FullyIndirectEnum": true,
32+
"GroupNumericLiterals": true,
33+
"IdentifiersMustBeASCII": true,
34+
"NeverForceUnwrap": false,
35+
"NeverUseForceTry": false,
36+
"NeverUseImplicitlyUnwrappedOptionals": false,
37+
"NoAccessLevelOnExtensionDeclaration": false,
38+
"NoAssignmentInExpressions": true,
39+
"NoBlockComments": true,
40+
"NoCasesWithOnlyFallthrough": true,
41+
"NoEmptyTrailingClosureParentheses": true,
42+
"NoLabelsInCasePatterns": true,
43+
"NoLeadingUnderscores": false,
44+
"NoParensAroundConditions": true,
45+
"NoVoidReturnOnFunctionSignature": true,
46+
"OmitExplicitReturns": true,
47+
"OneCasePerLine": true,
48+
"OneVariableDeclarationPerLine": true,
49+
"OnlyOneTrailingClosureArgument": true,
50+
"OrderedImports": true,
51+
"ReplaceForEachWithForLoop": true,
52+
"ReturnVoidInsteadOfEmptyTuple": true,
53+
"UseEarlyExits": false,
54+
"UseExplicitNilCheckInConditions": false,
55+
"UseLetInEveryBoundCaseVariable": false,
56+
"UseShorthandTypeNames": true,
57+
"UseSingleLinePropertyGetter": false,
58+
"UseSynthesizedInitializer": false,
59+
"UseTripleSlashForDocumentationComments": true,
60+
"UseWhereClausesInForLoops": false,
61+
"ValidateDocumentationComments": false
62+
}
63+
}

.swiftformat

Lines changed: 0 additions & 2 deletions
This file was deleted.

Benchmarks/Benchmarks/ElementaryBenchmarks/Benchmarks.swift

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,64 +69,74 @@ let benchmarks = { @Sendable in
6969
Benchmark("render merged attributes") { benchmark in
7070
benchmark.startMeasurement()
7171
for _ in benchmark.scaledIterations {
72-
try blackHole(await p {
73-
img(.class("1"), .style("1"), .id("old"))
74-
.attributes(.class("2"), .style("2"))
75-
.attributes(.id("new"))
76-
}.renderAsync())
72+
try blackHole(
73+
await p {
74+
img(.class("1"), .style("1"), .id("old"))
75+
.attributes(.class("2"), .style("2"))
76+
.attributes(.id("new"))
77+
}.renderAsync()
78+
)
7779
}
7880
}
7981

8082
Benchmark("render tuples") { benchmark in
8183
for _ in benchmark.scaledIterations {
82-
try blackHole(await div {
83-
img()
84-
img()
85-
img()
86-
img()
87-
div {
84+
try blackHole(
85+
await div {
8886
img()
8987
img()
9088
img()
9189
img()
9290
div {
9391
img()
9492
img()
93+
img()
94+
img()
95+
div {
96+
img()
97+
img()
98+
}
9599
}
96-
}
97-
}.renderAsync())
100+
}.renderAsync()
101+
)
98102
}
99103
}
100104

101105
Benchmark("render array") { benchmark in
102106
for _ in benchmark.scaledIterations {
103-
try blackHole(await div {
104-
for i in 0 ..< 1000 {
105-
img(.id("\(i)"))
106-
}
107-
}.renderAsync())
107+
try blackHole(
108+
await div {
109+
for i in 0..<1000 {
110+
img(.id("\(i)"))
111+
}
112+
}.renderAsync()
113+
)
108114
}
109115
}
110116

111117
Benchmark("render sequence") { benchmark in
112118
for _ in benchmark.scaledIterations {
113-
try blackHole(await div {
114-
ForEach(0 ..< 1000) { i in
115-
img(.id("\(i)"))
116-
}
117-
}.renderAsync())
119+
try blackHole(
120+
await div {
121+
ForEach(0..<1000) { i in
122+
img(.id("\(i)"))
123+
}
124+
}.renderAsync()
125+
)
118126
}
119127
}
120128

121129
Benchmark("render text") { benchmark in
122130
for _ in benchmark.scaledIterations {
123-
try blackHole(await div {
124-
"Hello, World!"
125-
"This is a paragraph."
126-
"Some interpolation \("maybe")"
127-
i { "Italic" }
128-
b { "Bold" }
129-
}.renderAsync())
131+
try blackHole(
132+
await div {
133+
"Hello, World!"
134+
"This is a paragraph."
135+
"Some interpolation \("maybe")"
136+
i { "Italic" }
137+
b { "Bold" }
138+
}.renderAsync()
139+
)
130140
}
131141
}
132142

@@ -146,15 +156,16 @@ let benchmarks = { @Sendable in
146156
"Swift"
147157
}
148158
ul(.class("fancy-list")) {
149-
ForEach(0 ..< 1000) { i in
159+
ForEach(0..<1000) { i in
150160
MyCustomElement {
151161
MyListItem(number: i)
152162
}
153163
HTMLComment("This is a comment")
154164
}
155165
}
156166
}
157-
}.renderAsync())
167+
}.renderAsync()
168+
)
158169
}
159170
}
160171

@@ -174,15 +185,16 @@ let benchmarks = { @Sendable in
174185
"Swift"
175186
}
176187
ul(.class("fancy-list")) {
177-
ForEach(0 ..< 1000) { i in
188+
ForEach(0..<1000) { i in
178189
MyCustomElement {
179190
MyListItem(number: i)
180191
}
181192
HTMLComment("This is a comment")
182193
}
183194
}
184195
}
185-
}.render())
196+
}.render()
197+
)
186198
}
187199
}
188200
}

Benchmarks/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
],
1919
path: "Benchmarks/ElementaryBenchmarks",
2020
plugins: [
21-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
21+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
2222
]
23-
),
23+
)
2424
]
2525
)

Examples/HummingbirdDemo/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import PackageDescription
44
let package = Package(
55
name: "HummingbirdDemo",
66
platforms: [
7-
.macOS(.v14),
7+
.macOS(.v14)
88
],
99
products: [
10-
.executable(name: "App", targets: ["App"]),
10+
.executable(name: "App", targets: ["App"])
1111
],
1212
dependencies: [
1313
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
@@ -21,6 +21,6 @@ let package = Package(
2121
.product(name: "Elementary", package: "elementary"),
2222
],
2323
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
24-
),
24+
)
2525
]
2626
)

Examples/HummingbirdDemo/Sources/App/Pages.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct GreetingPage: HTML {
5959
}
6060
} else {
6161
ul {
62-
ForEach(0 ..< greetingCount) { i in
62+
ForEach(0..<greetingCount) { i in
6363
li {
6464
"Hello there, \(name)!"
6565
// demo of conditional styling (should be done with CSS in real life)

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.library(
2222
name: "Elementary",
2323
targets: ["Elementary"]
24-
),
24+
)
2525
],
2626
targets: [
2727
.target(

[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44
let shouldBuildForEmbedded = Context.environment["JAVASCRIPTKIT_EXPERIMENTAL_EMBEDDED_WASM"].flatMap(Bool.init) ?? false
55

66
var featureFlags: [SwiftSetting] = [
7-
.enableUpcomingFeature("ExistentialAny"),
7+
.enableUpcomingFeature("ExistentialAny")
88
]
99

1010
if shouldBuildForEmbedded {
@@ -31,7 +31,7 @@ let package = Package(
3131
.library(
3232
name: "Elementary",
3333
targets: ["Elementary"]
34-
),
34+
)
3535
],
3636
targets: [
3737
.target(

Sources/Elementary/Core/AsyncContent.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ public struct AsyncContent<Content: HTML>: HTML, Sendable {
2424
}
2525

2626
@inlinable @inline(__always)
27-
public static func _render<Renderer: _HTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) {
27+
public static func _render<Renderer: _HTMLRendering>(
28+
_ html: consuming Self,
29+
into renderer: inout Renderer,
30+
with context: consuming _RenderingContext
31+
) {
2832
context.assertionFailureNoAsyncContext(self)
2933
}
3034

3135
@inlinable @inline(__always)
32-
public static func _render<Renderer: _AsyncHTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) async throws {
36+
public static func _render<Renderer: _AsyncHTMLRendering>(
37+
_ html: consuming Self,
38+
into renderer: inout Renderer,
39+
with context: consuming _RenderingContext
40+
) async throws {
3341
try await Content._render(await html.content(), into: &renderer, with: context)
3442
}
3543
}

0 commit comments

Comments
 (0)