Search code examples
c#code-formattingrider

Rider - place curly bracket with offset based on the begining of the parent level, not the parent declaration


I use JetBrains Rider 2022.2.3 Build #RD-222.4167.23, built on September 9, 2022

I want curly braces to be positioned based on the beginning of the level, not the declaration.

For example, I want

var person = new Person { FirstName = "John", Emails = new [] { "a@b.c", "d@e.f" }, }, PhoneNumbers = new [] { "0123456789", "0987654321" } };

to look like

var person = new Person
{
    FirstName = "John",
    Emails = new [] 
    {
        "a@b.c",
        "d@e.f"
    },
    PhoneNumbers = new []
    {
        "0123456789",
        "0987654321"
    }
}

where the braces are under beginning of the level

and not like

var person = new Person
             {
                 FirstName = "John",
                 Emails = new [] 
                          {
                              "a@b.c",
                              "d@e.f"
                          },
                 PhoneNumbers = new []
                                {
                                    "0123456789",
                                    "0987654321"
                                }
             };

where the braces are under the beginning of the declaration.

This allows to read longer lines without scrolling right and also gives (me) better readability as every level starts on the same column and is not based on the length of property name, as in my example if I have Emails and PhoneNumbers properties and the braces are on different offset for the same levels.

But the main reason for this is to not break formatting of the code from other colleagues who use Visual Studio, as I am the only one who use Rider in the team and although I like it, I cannot manually change all the formatting mess ups before every pull request submit and opening the code in Visual Studio and re-format and save it seems counter-productive.

Is it possible to do and how it can be done if so? I found curly braces settings in the Braces Layout for the language, but there are 3 "at next line" formatting options and neither does what I need.


Solution

  • Try disabling Array, object and collection initializer (under File | Settings | Editor | Code Style | C# | Tabs, Indents Alignment):
    enter image description here