Skip to content

[Bug]: Unexpected behavior wrt. raw-strings in lambda expressions #1940

Closed

Description

@penenkel

Description

I found the result of formatting the following code unexpected.

  • For the variable I would have liked the starting quotes to remain on a separate line and aligned the same wrt. the other lines of the raw string. But I can accept that this is a stylistic choice and that moving the starting quotes up is equally valid.
  • For the lambda I would have expected the same behavior: Either move the starting quotes up one line OR keep the alignment of all four lines the same.

The good news is, that the value of the string itself remains the same across all these variants, so it is not a critical bug. It is more a question of whether it is an intentional stylistic choice or an accidental confluence of formatting rules.

Steps to Reproduce

Input:

using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
        var bar = 
        """
        a
            b
        """;
		Func<int, string> foo = _ => 
		"""
		a
		    b
		""";
		Console.WriteLine(bar);
		Console.WriteLine(foo(2));
	}
}

Expected Behavior

using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var bar = 
            """
            a
                b
            """;
        Func<int, string> foo = _ => 
            """
            a
                b
            """;
        Console.WriteLine(bar);
        Console.WriteLine(foo(2));
    }
}

OR

using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var bar = """
            a
                b
            """;
        Func<int, string> foo = _ => """
            a
                b
            """;
        Console.WriteLine(bar);
        Console.WriteLine(foo(2));
    }
}

Actual Behavior

Formatted with csharpier 1.4.0:

using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var bar = """
            a
                b
            """;
        Func<int, string> foo = _ =>
            """
                a
                    b
                """;
        Console.WriteLine(bar);
        Console.WriteLine(foo(2));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions