Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrettyPrinter reports wrong line numbers #882

Open
bkolb opened this issue Nov 23, 2024 · 2 comments
Open

PrettyPrinter reports wrong line numbers #882

bkolb opened this issue Nov 23, 2024 · 2 comments

Comments

@bkolb
Copy link

bkolb commented Nov 23, 2024

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 added a commit to bkolb/swift-format that referenced this issue Nov 23, 2024
This is to reproduce issue swiftlang#882.
No fix is provided yet.

Issue: swiftlang#882
bkolb added a commit to bkolb/swift-format that referenced this issue Nov 23, 2024
This is to reproduce issue swiftlang#882.
No fix is provided yet.

Issue: swiftlang#882
@bkolb
Copy link
Author

bkolb commented Nov 23, 2024

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.

bkolb added a commit to bkolb/swift-format that referenced this issue Nov 23, 2024
The reason for the wrong line number were multiline
comments.
In to accomodate for this, we now check the string
while writing for new lines and increment the line
count accordingly.

Issue: swiftlang#882
@ahoppen
Copy link
Member

ahoppen commented Nov 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants