nicklockwood / SwiftFormat

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

'hoistTry' rule continues to have an issue in strings #1407

Closed foscomputerservices closed 1 year ago

foscomputerservices commented 1 year ago

Following up on #1403, here is a different format that continues to have an issue in 0.51.4:

public struct TestHoistTry {
    public init() throws {
        let index = 1
        let str = "" +
            "more text" +
            "&enrolments[\(index) ][userid]=\(try Foo.tryMe())" +
            "even more text"
        print(str)
    }
}

enum Foo {
    static func tryMe() throws -> String { ", World!" }
}

After running swiftformat, you will get:

public struct TestHoistTry {
    public init() throws {
        let index = 1
        let str = "" +
            "more text" +
            "&enrolments[\(index) try  ][userid]=\(Foo.tryMe())" + // <-- try in wrong location
            "even more text"
        print(str)
    }
}

enum Foo {
    static func tryMe() throws -> String { ", World!" }
}

Environment

% swiftformat --version 0.51.4

% swift --version swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: arm64-apple-macosx13.0

% xcodebuild -version Xcode 14.2 Build version 14C18

nicklockwood commented 1 year ago

@foscomputerservices fixed in 0.51.5

foscomputerservices commented 1 year ago

Hi @nicklockwood. Thank you so much for your efforts with swiftformat and this particular issue. Sadly there continue to be small issues. Now, when using 0.51.5 the following fails:

            return str +
                "&enrolments[\(index)][roleid]=\(MoodleRoles.studentRole.rawValue)" +
                "&enrolments[\(index)][userid]=\(try user.requireMoodleID())" +
                "&enrolments[\(index)][courseid]=\(moodleCourseId)"

It is formatted to:

            return str +
                "&enrolments[\(index)][roleid]=\(MoodleRoles.studentRole.rawValue) try " +
                "&enrolments[\(index)][userid]=\(user.requireMoodleID())" +
                "&enrolments[\(index)][courseid]=\(moodleCourseId)"