dotnet / dotnet/format

Indent of blocks inside chained method call

Open
#1,399 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
1.9k
Forks
173
Avg merge
10d 13h
Merged PRs (30d)
1

Description

Hi, i observe interesting behavior and can't quite understand why this happens and how to work around that. `dotnet format` and `Rider` format this code a bit differently and this blocks me from using `dotnet format` as linting tool after IDE.
**All options are defaults**. After fiddling with different settings, i reset Rider and removed `.editorconfig` because i can't find any relevant options in both tools and this way it should be easier to diagnose (maybe). Also, i'm not sure which variant is "correct" and maybe i should be filing a bug report to JetBrains :)

```cs
// formatted by dotnet format
var init1 = list.Select(x => new
{ // no indent
Key = x,
Value = x
});

var init2 = list.Select(x => new
{ // no indent
Key = x,
Value = x
})
.ToList();

var init3 = list.Where(x => x != null)
.Select(x => new
{ // indent
Key = x,
Value = x
})
.ToList();

var body1 = list.Select(x =>
{ // no indent
var a = 0;
return a;
});

var body2 = list.Select(x =>
{ // indent
var a = 0;
return a;
})
.ToList();

var body3 = list.Where(x => x != null)
.Select(x =>
{ // indent
var a = 0;
return a;
})
.ToList();
```

```cs
// formatted by Rider
var init1 = list.Select(x => new
{ // no indent
Key = x,
Value = x
});

var init2 = list.Select(x => new
{ // indent
Key = x,
Value = x
})
.ToList();

var init3 = list.Where(x => x != null)
.Select(x => new
{ // indent
Key = x,
Value = x
})
.ToList();

var body1 = list.Select(x =>
{ // no indent
var a = 0;
return a;
});

var body2 = list.Select(x =>
{ // indent
var a = 0;
return a;
})
.ToList();

var body3 = list.Where(x => x != null)
.Select(x =>
{ // indent
var a = 0;
return a;
})
.ToList();
```

dotnet format indents: `--+-++`
Rider indents: `-++-++`
`init2` gets different formatting

dotnet-format version is `5.1.225507`

PS is there any way to disable `WHITESPACE` but still get other nice things like `CHARSET` and `FINALNEWLINE`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.