swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.47k stars 227 forks source link

TrailingComma shows wrong line when AddLines present #737

Open cyrusdaboo opened 4 months ago

cyrusdaboo commented 4 months ago

Use swift-format lint on the following code:

class ABC {
    func method(a: String,
    b: String, c: String, d: String, e: String) -> String {
        let items = [
            "a",
        ]
    }
}

and it gives:

/Users/redacted/Documents/format.swift:7:16: warning: [TrailingComma] remove trailing comma from the last element in single line collection literal
format.swift:2:17: warning: [AddLines] add 1 line break
format.swift:3:1: warning: [Indentation] indent by 4 spaces
format.swift:3:47: warning: [AddLines] add 1 line break

Notice that the TrailingComma message's line number is 7 instead of 5. This seems to occur when there are AddLines messages also present.

Also note that the TrailingComma message shows the full path of the file and not the relative path like the other messages.

ahoppen commented 4 months ago

Synced to Apple’s issue tracker as rdar://127780416