dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.11k stars 4.04k forks source link

IDE0055: does not provide any control on nested for/foreach/while statements #64654

Open gavar opened 2 years ago

gavar commented 2 years ago

Version Used: 4.3.1

Steps to Reproduce:

using System;
using System.Linq;

public class Program
{
    private static void NestedForLoop()
    {
        for (var i = 0; i < 10; i++)
        for (var j = 0; j < 10; j++)
            Console.WriteLine("Hello World");
    }

    private static void NestedWhileLoop()
    {
        var a = 10;
        var b = 10;

        while (--a >= 0)
        while (--b >= 0)
            Console.WriteLine("Hello World");
    }

    private static void NestedForeachLoop()
    {
        foreach (var a in Enumerable.Range(1, 10))
        foreach (var b in Enumerable.Range(1, 10))
            Console.WriteLine("Hello World");
    }
}

Expected Behavior: I should be able to configure my settings such that this code isn't changed by IDE0055.

Actual Behavior: IDE0055 (formatting fixes in general) forces this to

using System;
using System.Linq;

public class Program
{
    private static void NestedForLoop()
    {
        for (var i = 0; i < 10; i++)
            for (var j = 0; j < 10; j++)
                Console.WriteLine("Hello World");
    }

    private static void NestedWhileLoop()
    {
        var a = 10;
        var b = 10;

        while (--a >= 0)
            while (--b >= 0)
                Console.WriteLine("Hello World");
    }

    private static void NestedForeachLoop()
    {
        foreach (var a in Enumerable.Range(1, 10))
            foreach (var b in Enumerable.Range(1, 10))
                Console.WriteLine("Hello World");
    }
}

Currently, it is not possible to make IDE0055 compatible with the following ReSharper formatting settings:

resharper_csharp_indent_nested_for_stmt = false
resharper_csharp_indent_nested_foreach_stmt = false
resharper_csharp_indent_nested_while_stmt = false

Links to ReShareprt documentation Indent nested 'for' statements Indent nested 'foreach' statements Indent nested 'while' statements

CyrusNajmabadi commented 2 years ago

@jmarolf @mikadumont can you add this to the extensible-formatting set of cases?

gavar commented 1 week ago

@CyrusNajmabadi any updates on this?

CyrusNajmabadi commented 1 week ago

@CyrusNajmabadi any updates on this?

No. There is no update on this.