nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.77k stars 629 forks source link

hoistTry rule issues #1518

Closed shredsonic closed 11 months ago

shredsonic commented 12 months ago

It looks like we ran into a couple of edge cases with try hoisting. Two of these seem to be the same scenario, while the third one is inside a raw string. We can ignore the raw string one, but I'm providing it here in case it's fixable. I checked these against the latest release: 0.52.2.

             .filter { $0.lastComponent == T.fileName + ".yml" }
             .map {
                 do {
-                    return Target<T>(
+                    return Target<T>try (
                         directory: $0.parent(),
-                        file: try parseFile(path: $0)
+                        file: parseFile(path: $0)
                     )
                 } catch {
                     fatalError("Failed to parse target: \(error)) at path: \($0)")
 extension IssueExplorerTests {
     func targetForModule(in resourceDirectory: String) throws -> Target<Module> {
         let dir = resourcesPath + "\(resourceDirectory)"
-        return Target<Module>(
+        return Target<Module>try (
             directory: dir,
-            file: try ManifestParser().parseFile(path: dir + "module.yml")
+            file: ManifestParser().parseFile(path: dir + "module.yml")
         )
     }
 }
             """
             public let \(object.varName) =
             \(tripleQuote)
-            \(try encode(object.object))
+            try \(encode(object.object))
             \(tripleQuote)

             """
nicklockwood commented 11 months ago

@zzt4 thanks for reporting these. Both are definitely fixable. In the meantime, manually moving the try to the correct place should prevent SwiftFormat from mangling these lines on the next run.

nicklockwood commented 11 months ago

@zzt4 fixed in 0.52.3