belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.41k stars 99 forks source link

Comment between attributes violates SA1515 #1252

Closed maurobringolf closed 5 months ago

maurobringolf commented 6 months ago

Input:

public class C {

    [A]

    // moves up
    [B]
    public void A()
    {
        var z = 1;

        // stays here
        var y = 2;
    }
}

Output:

public class C
{
    [A]
    // moves up
    [B]
    public void A()
    {
        var z = 1;

        // stays here
        var y = 2;
    }
}

Expected behavior: The autoformatting causes the code not to comply with SA1515. According to the docs this rule is not in conflict with the CSharpier format. I expect the output to build without formatting warnings when configured as described.


As far as I can tell this can be resolved in two ways:

  1. Keep whitespace before comments in all cases (if that's possible).
  2. Add SA1515 to the to-be-disabled rules

I would favor the second option.

belav commented 5 months ago

There is already logic for forcing a new line before the first attribute and removing blank lines between attributes. After looking into it - getting all of that to play nice with keeping/adding new lines before comments between attributes won't be straightforward. I'm good with adding SA1515 to the to-be-disabled list.