belav / csharpier

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

Code inside interpolated raw literals is not formatted #1308

Closed RReverser closed 3 months ago

RReverser commented 3 months ago

Input:

Minimal repro:

        var extensions =
                        $$"""
                                {{
                          $"""
                          nested
                          """
                                }}
                                """;

Output:

var extensions = $$"""
                                {{
                          $"""
                          nested
                          """
                                }}
                                """;

Expected behavior:

I saw that raw string literal formatting was implemented in https://github.com/belav/csharpier/issues/975 / https://github.com/belav/csharpier/pull/977, but for some reason it breaks when there are nested raw literals like in the example above (those are fairly common in complex codebase).

I'd expect those strings to be reindented just like they're when no nesting occurs, probably to something like this:

var extensions = $$"""
    {{
      $"""
      nested
      """
    }}
    """;
RReverser commented 3 months ago

@belav Looking at changes in #977, it seems that the issue is that it never accounted for interpolated raw strings to begin with?

RReverser commented 3 months ago

Yeah looks like it's not just nested raw literals; no formatting whatsoever currently happens inside interpolated raw strings. An even simpler example:

        var extensions =
                        $$"""
                                {{
                          foo
                                    .bar
                                 .baz(
                               )
                                }}
                                """;
RReverser commented 3 months ago

Ah and now that I figured it's a general issue, I can see it's a duplicate of #1136, so closing.