Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build warnings #822

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {

override func visit(_ node: GenericParameterSyntax) -> SyntaxVisitorContinueKind {
before(node.firstToken(viewMode: .sourceAccurate), tokens: .open)
after(node.eachKeyword, tokens: .break)
after(node.specifier, tokens: .break)
after(node.colon, tokens: .break)
if let trailingComma = node.trailingComma {
after(trailingComma, tokens: .close, .break(.same))
Expand Down
8 changes: 7 additions & 1 deletion Sources/generate-swift-format/FileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ protocol FileGenerator {
func write(into handle: FileHandle) throws
}

private struct FailedToCreateFileError: Error {
let url: URL
}

extension FileGenerator {
/// Generates a file at the given URL, overwriting it if it already exists.
func generateFile(at url: URL) throws {
Expand All @@ -27,7 +31,9 @@ extension FileGenerator {
try fm.removeItem(at: url)
}

fm.createFile(atPath: url.path, contents: nil, attributes: nil)
if !fm.createFile(atPath: url.path, contents: nil, attributes: nil) {
throw FailedToCreateFileError(url: url)
}
let handle = try FileHandle(forWritingTo: url)
defer { handle.closeFile() }

Expand Down
7 changes: 6 additions & 1 deletion Tests/swift-formatTests/Utilities/FileIteratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ extension FileIteratorTests {
let fileURL = tmpURL(path)
try FileManager.default.createDirectory(
at: fileURL.deletingLastPathComponent(), withIntermediateDirectories: true)
FileManager.default.createFile(atPath: fileURL.path, contents: Data())
struct FailedToCreateFileError: Error {
let url: URL
}
if !FileManager.default.createFile(atPath: fileURL.path, contents: Data()) {
throw FailedToCreateFileError(url: fileURL)
}
}

/// Create a symlink between files or directories in the test's temporary space.
Expand Down