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

Comments break indentation of subsequent lines #894

Open
jods4 opened this issue May 8, 2023 · 1 comment
Open

Comments break indentation of subsequent lines #894

jods4 opened this issue May 8, 2023 · 1 comment

Comments

@jods4
Copy link

jods4 commented May 8, 2023

Tested with 0.24.2, this can be reproduced in the playground:

// Input
public class C {
    public void Test() { 
        this
            // This is a comment 
            .LongUglyMethod();
    }
}

// Playground output
// Observe that the comment and .LongUglyMethod() are not indented
public class C
{
    public void Test()
    {
        this
        // This is a comment
        .LongUglyMethod();
    }
}

// Expected output
public class C
{
    public void Test()
    {
        this
            // This is a comment
            .LongUglyMethod();
    }
}

This seems to only occur if the first line is a comment.
If the comment line follows an already indented line, everything seems ok:

// Input
public class C {
    public void Test() { 
        services
        .A()
        // This is a comment 
        .C();
    }
}

// Output is ok
public class C
{
    public void Test()
    {
        services
            .A()
            // This is a comment
            .C();
    }
}
@jods4
Copy link
Author

jods4 commented Jun 26, 2023

Maybe related (but maybe not)?

Here's another bad case I observed involving comments messing subsequent formatting.

When you put a comment on a method parameter that has an attribute, the comment forces a line break between attribute and parameter name. This is inconsistent with the formatting without comment, and doesn't look good on short lines.

// Input and expected -> ok!
void TestALongMethodWithAttributesOnParameter(
    [FromBody] string name,
    [FromQuery] List<string> manyTags
) { }

// Input and expected -> not ok
void TestALongMethodWithAttributesOnParameterAndComment(
    // This is a comment on name
    [FromBody] string name, 
    [FromQuery] List<string> manyTags
) { }

// Actual playground output for 2nd method
void TestALongMethodWithAttributesOnParameterAndComment(
    // This is a comment on name
    [FromBody]
        string name,
    [FromQuery] List<string> manyTags
) { }

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

No branches or pull requests

2 participants