swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.54k stars 231 forks source link

PrettyPrinter reports wrong line numbers #882

Open bkolb opened 2 days ago

bkolb commented 2 days ago

I have a file with a copyright header. This leads to the reporting of wrong line numbers in rules like EndOfLineComment

Here is an example where the reporting works as expected:

final class A {
    @Test func b() throws {
        doSomethingInAFunctionWithAVeryLongName()  1️⃣// Here we have a very long comment that should not be here because it is far too long
    }
}

Changing the input to the following will fail:

// Copyright (C) 2024 My Coorp. All rights reserved.
//
// This document is the property of My Coorp.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// My Coorp.

final class A {
    @Test func b() throws {
        doSomethingInAFunctionWithAVeryLongName()  1️⃣// Here we have a very long comment that should not be here because it is far too long
    }
}

The error is here is reported in location (line:col 5:52) and should be in (line:col 12:52)

bkolb commented 2 days ago

My suspicion is, that the pretty printer is thrown off by multiline comments. In that case, it seems to add only one line for an entire comment block.

ahoppen commented 1 day ago

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