belav / csharpier

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

fixing issue when formatting with tabs that would convert tabs in com… #1344

Closed belav closed 2 months ago

belav commented 2 months ago

…ments into spaces.

closes #1343

belav commented 2 months ago

This was a pretty quick fix, but leads to a question of what to do when the line in the comments is tabs followed by spaces. This is what I ended up doing. All the leading whitespace in here is tabs unless otherwise indicated by the comments. I think the altenative would be to turn anything less than a full tab into 1 tab, unless it matches the pattern of that first comment.

Or another alternative would be to try to leave alone any whitespace that is "part of the block". Meaning the 3 comments below all start with 2 indents that are tabs, and any whitespace after that is left alone because it is in the block of the multiline comment.


public class Foo
{
    /**
     * comment - existing behavior, keeps the single space to align the *
     */
    public class Bar { }

    public void SomeFunction()
    {
        /*
        The following line is an example with an indent:
            This line is indented by one tab.
        */
        /*
        The following line is an example with an indent:
            This line is indented by 4 spaces but will be converted to 1 tab
        */
        /*
        The following line is an example with an indent:
           This line is indented by 3 spaces but will be left as 3 spaces
        */
    }
}