Skip to content

[Bug]: Leading comment causes with expression to split into multiple lines #1882

Description

@JimmyCushnie

Description

By default, CSharpier allows with expressions to stay on one line. However, if a comment is added before the with expression, CSharpier will unexpectedly split the with into 4+ lines.

Steps to Reproduce

Try the following two inputs and observe the outputs.

Input 1

public class ClassName {
    public void Method() { 
        var apples = new { Item = "Apples", Price = 1.19m };
        
        var saleApples = apples with { Price = 0.79m };
    }
}

Input 2

public class ClassName {
    public void Method() { 
        var apples = new { Item = "Apples", Price = 1.19m };
        
        // test
        var saleApples = apples with { Price = 0.79m };
    }
}

Expected Behavior

Output 1

public class ClassName
{
    public void Method()
    {
        var apples = new { Item = "Apples", Price = 1.19m };

        var saleApples = apples with { Price = 0.79m };
    }
}

Output 2

public class ClassName
{
    public void Method()
    {
        var apples = new { Item = "Apples", Price = 1.19m };

        // test
        var saleApples = apples with { Price = 0.79m };
    }
}

Actual Behavior

Output 1

public class ClassName
{
    public void Method()
    {
        var apples = new { Item = "Apples", Price = 1.19m };

        var saleApples = apples with { Price = 0.79m };
    }
}

Output 2

public class ClassName
{
    public void Method()
    {
        var apples = new { Item = "Apples", Price = 1.19m };

        // test
        var saleApples = apples with
        {
            Price = 0.79m,
        };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions