Weird initializer indentation
- Dominant language
- No language data
- Stars
- 1.9k
- Forks
- 173
- Avg merge
- 10d 13h
- Merged PRs (30d)
- 1
Description
Indentation of the object/anonymous object initializer block is quite weird in my opinion — one level of indentation is missing.
Consider the following example
```
private static int Foo(object obj, int number)
{
return 0;
}
private static void Bar()
{
const int number = 1;
var result = Foo(new
{
Prop1 = "",
Prop2 = ""
},
number);
}
```
This is how `dotnet-format` reformats it
```
private static int Foo(object obj, int number)
{
return 0;
}
private static void Bar()
{
const int number = 1;
var result = Foo(new
{
Prop1 = "",
Prop2 = ""
},
number);
}
```
Basically it always removes indentation for the initializer block, thus resulting in inconsistent indentation for the method parameters.
It looks even worse if we add some fluent style method invocations.
```
private static void Bar()
{
const int number = 1;
var result = Foo(new
{
Prop1 = "",
Prop2 = ""
},
number)
.GetHashCode()
.ToString();
}
```
Is there a way to keep indentation like in the initial snippet with initializer indented consistently with the rest of the parameters?
E.g resharper formats it the first way and it's more reasonable in general.
```
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.101\
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
3.1.100 [C:\Program Files\dotnet\sdk]
3.1.416 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]
dotnet format --version
6.0.252703+68bc36719088c86b0ff01334039b0611741b8276
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.