Skip to content

[Bug]: Unable to ignore csharpier formatting within case statement group #1824

@ngbrown

Description

@ngbrown

Description

When formatting my code, I have some verbatim strings where the first line is being indented in a way I don't want and adding // csharpier-ignore or // csharpier-ignore-start doesn't skip over over that block.

I can't use raw string literals because this file is in project still targeting .NET 4.7.2 and raw string literals are not available in C# 7.3. The project is also still opened in Visual Studio 2019, which only supports up to C# 9.0, not C# 11, where string literals were introduced.

Steps to Reproduce

Have a file with the following content:

namespace format_test;

public class Class1
{
    public void IHaveAConfiguration(string value)
    {
        switch (value)
        {
            case "aoeuao":
                // csharpier-ignore-start
                var table = TableFromString(
@"			| Field         | Value |
			| ValueA        | 1     |
			| ValueB        | AC08  |"
                );
                // csharpier-ignore-end
                break;
        }

        // ... do things with table
    }

    private static string TableFromString(string tableString)
    {
        // ... implementation to convert string to table
        return tableString; // Placeholder return
    }
}

Run csharpier on it.

Expected Behavior

Using // csharpier-ignore should work, and so should the // csharpier-ignore-start and // csharpier-ignore-end pair.

Actual Behavior

When ran through csharpier the first line of the string becomes indented and making the table no longer line up like this:

            // csharpier-ignore-start
            var table = CommonStepHelpers.TableFromString(
                @"			| Field         | Value |
			| ValueA        | 1     |
			| ValueB        | AC08  |"
            );
            // csharpier-ignore-end

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