From d2b01fc52c665fbc4ca039e99a94b7348c344c48 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Sun, 29 Sep 2024 08:12:39 -0700 Subject: [PATCH 1/2] Fix build warning: `eachKeyword` was renamed to `specifier` --- Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index c3709c60c..a8298eed5 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -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)) From acc3c6c933b6564c4d4a640ccd02a911976b7513 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Sun, 29 Sep 2024 08:55:40 -0700 Subject: [PATCH 2/2] =?UTF-8?q?Don=E2=80=99t=20discard=20the=20return=20va?= =?UTF-8?q?lue=20of=20`FileManager.createFile`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/generate-swift-format/FileGenerator.swift | 8 +++++++- Tests/swift-formatTests/Utilities/FileIteratorTests.swift | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/generate-swift-format/FileGenerator.swift b/Sources/generate-swift-format/FileGenerator.swift index 85a8861bc..c4ba1f553 100644 --- a/Sources/generate-swift-format/FileGenerator.swift +++ b/Sources/generate-swift-format/FileGenerator.swift @@ -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 { @@ -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() } diff --git a/Tests/swift-formatTests/Utilities/FileIteratorTests.swift b/Tests/swift-formatTests/Utilities/FileIteratorTests.swift index 5bfe5bb18..868758bbe 100644 --- a/Tests/swift-formatTests/Utilities/FileIteratorTests.swift +++ b/Tests/swift-formatTests/Utilities/FileIteratorTests.swift @@ -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.