Skip to content

Commit a12d4eb

Browse files
kylehowellsclaude
andcommitted
Fix swiftformat lint warnings
Auto-fixed by running swiftformat locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 0e803dd commit a12d4eb

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed

Examples/fetchpage/main.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@
1111

1212
import Foundation
1313
#if canImport(FoundationNetworking)
14-
import FoundationNetworking
14+
import FoundationNetworking
1515
#endif
1616
import justhtml
1717

1818
func printUsage() {
1919
let name = (CommandLine.arguments.first as NSString?)?.lastPathComponent ?? "fetchpage"
2020
FileHandle.standardError.write(Data("""
2121
Usage: \(name) <url> [selector]
22-
22+
2323
Fetch HTML from a URL and query elements using CSS selectors.
24-
24+
2525
Arguments:
2626
url URL to fetch HTML from
2727
selector CSS selector to query (default: prints page title)
28-
28+
2929
Options:
3030
-t, --title Also print page title before results
3131
-a, --attr NAME Print attribute value instead of text
3232
-h, --help Show this help message
33-
33+
3434
Examples:
3535
\(name) https://en.wikipedia.org/
3636
\(name) https://en.wikipedia.org/ "#mp-itn b a"
3737
\(name) https://en.wikipedia.org/ "#mp-itn b a" --attr title
3838
\(name) https://example.com "a[href]" --attr href
39-
39+
4040
""".utf8))
4141
}
4242

@@ -58,11 +58,13 @@ func resolveURL(_ href: String, base: URL) -> String {
5858
return href
5959
}
6060

61+
// MARK: - FetchResult
62+
6163
/// Container for URL session result to avoid concurrency issues
6264
final class FetchResult: @unchecked Sendable {
63-
var data: Data?
64-
var response: URLResponse?
65-
var error: Error?
65+
var data: Data? = nil
66+
var response: URLResponse? = nil
67+
var error: Error? = nil
6668
}
6769

6870
/// Fetch HTML content from a URL synchronously
@@ -107,7 +109,7 @@ func fetchHTML(from urlString: String) throws -> (String, URL) {
107109
// Determine encoding from Content-Type header, default to UTF-8
108110
var encoding = String.Encoding.utf8
109111
if let contentType = httpResponse.value(forHTTPHeaderField: "Content-Type"),
110-
contentType.lowercased().contains("charset=iso-8859-1")
112+
contentType.lowercased().contains("charset=iso-8859-1")
111113
{
112114
encoding = .isoLatin1
113115
}
@@ -126,6 +128,7 @@ func getTitle(_ doc: JustHTML) -> String? {
126128
guard let titleElement = try? doc.query("title").first else {
127129
return nil
128130
}
131+
129132
return titleElement.toText().trimmingCharacters(in: .whitespacesAndNewlines)
130133
}
131134

Sources/swift-justhtml/Node.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ public final class Node {
518518
of: "\\s+",
519519
with: " ",
520520
options: .regularExpression
521-
).trimmingCharacters(in: .whitespacesAndNewlines)
521+
)
522+
.trimmingCharacters(in: .whitespacesAndNewlines)
522523
}
523524
return result
524525
}

Tests/swift-justhtmlTests/BenchmarkTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,3 @@ func generateMalformedHTML(elements: Int) -> String {
351351
html += "</body></html>"
352352
return html
353353
}
354-

Tests/swift-justhtmlTests/FuzzerTests.swift

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -701,19 +701,22 @@ private let fuzzUnicodeSpecial = [
701701

702702
/// Generate emoji-heavy text content
703703
private func fuzzEmojiText() -> String {
704-
let count = Int.random(in: 1...10)
704+
let count = Int.random(in: 1 ... 10)
705705
var result = ""
706-
for _ in 0..<count {
707-
let choice = Int.random(in: 0..<4)
706+
for _ in 0 ..< count {
707+
let choice = Int.random(in: 0 ..< 4)
708708
switch choice {
709-
case 0:
710-
result += fuzzEmoji.randomElement()!
711-
case 1:
712-
result += fuzzUnicodeScripts.randomElement()!
713-
case 2:
714-
result += fuzzUnicodeSpecial.randomElement()!
715-
default:
716-
result += fuzzRandomString(minLen: 1, maxLen: 5)
709+
case 0:
710+
result += fuzzEmoji.randomElement()!
711+
712+
case 1:
713+
result += fuzzUnicodeScripts.randomElement()!
714+
715+
case 2:
716+
result += fuzzUnicodeSpecial.randomElement()!
717+
718+
default:
719+
result += fuzzRandomString(minLen: 1, maxLen: 5)
717720
}
718721
}
719722
return result
@@ -838,24 +841,28 @@ private func fuzzEmojiAtBoundaries() -> String {
838841
/// Generate completely random Unicode strings
839842
private func fuzzRandomUnicode(length: Int) -> String {
840843
var result = ""
841-
for _ in 0..<length {
842-
let choice = Int.random(in: 0..<5)
844+
for _ in 0 ..< length {
845+
let choice = Int.random(in: 0 ..< 5)
843846
switch choice {
844-
case 0:
845-
result += fuzzEmoji.randomElement()!
846-
case 1:
847-
result += fuzzUnicodeScripts.randomElement()!
848-
case 2:
849-
result += fuzzUnicodeSpecial.randomElement()!
850-
case 3:
851-
// Random valid Unicode scalar
852-
if let scalar = UnicodeScalar(UInt32.random(in: 0x20...0x10FFFF)) {
853-
if scalar.isASCII || !scalar.properties.isNoncharacterCodePoint {
854-
result.append(Character(scalar))
847+
case 0:
848+
result += fuzzEmoji.randomElement()!
849+
850+
case 1:
851+
result += fuzzUnicodeScripts.randomElement()!
852+
853+
case 2:
854+
result += fuzzUnicodeSpecial.randomElement()!
855+
856+
case 3:
857+
// Random valid Unicode scalar
858+
if let scalar = UnicodeScalar(UInt32.random(in: 0x20 ... 0x10FFFF)) {
859+
if scalar.isASCII || !scalar.properties.isNoncharacterCodePoint {
860+
result.append(Character(scalar))
861+
}
855862
}
856-
}
857-
default:
858-
result += String((0..<Int.random(in: 1...3)).map { _ in "abcdef".randomElement()! })
863+
864+
default:
865+
result += String((0 ..< Int.random(in: 1 ... 3)).map { _ in "abcdef".randomElement()! })
859866
}
860867
}
861868
return result
@@ -875,21 +882,21 @@ private func fuzzRandomUnicode(length: Int) -> String {
875882

876883
// Test emoji in tag names
877884
print(" Testing emoji in tag names...")
878-
for _ in 0..<testsPerCategory {
885+
for _ in 0 ..< testsPerCategory {
879886
let html = fuzzEmojiInTagName()
880887
let doc = try JustHTML(html)
881888
let output = doc.toHTML()
882889
// Verify emoji survives round-trip
883890
for emoji in fuzzEmoji where html.contains(emoji) {
884891
#expect(output.contains(emoji) || doc.toText().contains(emoji),
885-
"Emoji should survive parsing: \(emoji)")
892+
"Emoji should survive parsing: \(emoji)")
886893
}
887894
completed += 1
888895
}
889896

890897
// Test emoji in attributes
891898
print(" Testing emoji in attributes...")
892-
for _ in 0..<testsPerCategory {
899+
for _ in 0 ..< testsPerCategory {
893900
let html = fuzzEmojiInAttributes()
894901
let doc = try JustHTML(html)
895902
_ = doc.toHTML()
@@ -898,7 +905,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
898905

899906
// Test emoji mid-tag
900907
print(" Testing emoji mid-tag...")
901-
for _ in 0..<testsPerCategory {
908+
for _ in 0 ..< testsPerCategory {
902909
let html = fuzzEmojiMidTag()
903910
let doc = try JustHTML(html)
904911
_ = doc.toHTML()
@@ -907,7 +914,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
907914

908915
// Test emoji in comments
909916
print(" Testing emoji in comments...")
910-
for _ in 0..<testsPerCategory {
917+
for _ in 0 ..< testsPerCategory {
911918
let html = fuzzEmojiInComments()
912919
let doc = try JustHTML(html)
913920
_ = doc.toHTML()
@@ -916,7 +923,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
916923

917924
// Test emoji with entities
918925
print(" Testing emoji with entities...")
919-
for _ in 0..<testsPerCategory {
926+
for _ in 0 ..< testsPerCategory {
920927
let html = fuzzEmojiWithEntities()
921928
let doc = try JustHTML(html)
922929
_ = doc.toHTML()
@@ -925,7 +932,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
925932

926933
// Test emoji in raw text elements
927934
print(" Testing emoji in script/style/title...")
928-
for _ in 0..<testsPerCategory {
935+
for _ in 0 ..< testsPerCategory {
929936
let html = fuzzEmojiInRawText()
930937
let doc = try JustHTML(html)
931938
_ = doc.toHTML()
@@ -934,7 +941,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
934941

935942
// Test emoji at byte boundaries
936943
print(" Testing emoji at byte boundaries...")
937-
for _ in 0..<testsPerCategory {
944+
for _ in 0 ..< testsPerCategory {
938945
let html = fuzzEmojiAtBoundaries()
939946
let doc = try JustHTML(html)
940947
_ = doc.toHTML()
@@ -943,8 +950,8 @@ private func fuzzRandomUnicode(length: Int) -> String {
943950

944951
// Test random Unicode soup
945952
print(" Testing random Unicode strings...")
946-
for _ in 0..<testsPerCategory {
947-
let unicode = fuzzRandomUnicode(length: Int.random(in: 10...100))
953+
for _ in 0 ..< testsPerCategory {
954+
let unicode = fuzzRandomUnicode(length: Int.random(in: 10 ... 100))
948955
let html = "<div>\(unicode)</div>"
949956
let doc = try JustHTML(html)
950957
_ = doc.toHTML()
@@ -953,7 +960,7 @@ private func fuzzRandomUnicode(length: Int) -> String {
953960

954961
// Test combined chaos
955962
print(" Testing combined Unicode chaos...")
956-
for _ in 0..<testsPerCategory {
963+
for _ in 0 ..< testsPerCategory {
957964
var parts: [String] = []
958965
parts.append(fuzzEmojiInTagName())
959966
parts.append(fuzzEmojiInAttributes())

0 commit comments

Comments
 (0)