dotnet / dotnet/format

"Unmerged change from project" after running dotnet format

Open
#1,634 9 comments 10 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

When starting with a piece of code like this where I purposely set the if condition all in one line:

```csharp
public static OptionsBuilder AddOptionsValue(this IServiceCollection services, IConfiguration configuration)
where T : class, new()
{
if (services is null) { throw new ArgumentNullException(nameof(services)); }

return services
.AddOptions()
.Bind(configuration)
.AddOptionsValue();
}
```

After running dotnet format I get the following:

```csharp
public static OptionsBuilder AddOptionsValue(this IServiceCollection services, IConfiguration configuration)
where T : class, new()
{

/* Unmerged change from project 'DotNet.Sdk.Extensions(net5.0)'
Before:
if (services is null) { throw new ArgumentNullException(nameof(services)); }
After:
if (services is null)
{
throw new ArgumentNullException(nameof(services)); }
*/

/* Unmerged change from project 'DotNet.Sdk.Extensions(net6.0)'
Before:
if (services is null) { throw new ArgumentNullException(nameof(services)); }
After:
if (services is null)
{
throw new ArgumentNullException(nameof(services)); }
*/
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

return services
.AddOptions()
.Bind(configuration)
.AddOptionsValue();
}
```

I seem to be able to reproduce this reliable from [this repo of mine](https://github.com/edumserrano/dotnet-sdk-extensions). The file I changed and mention in this example was this one: [OptionsBuilderExtensions.cs](https://github.com/edumserrano/dotnet-sdk-extensions/blob/4223234b3678447f479c7f07179ab0d24b161270/src/DotNet.Sdk.Extensions/Options/OptionsBuilderExtensions.cs).

The [project](https://github.com/edumserrano/dotnet-sdk-extensions/blob/main/src/DotNet.Sdk.Extensions/DotNet.Sdk.Extensions.csproj) where this happens targets multiple frameworks: `netcoreapp3.1;net5.0;net6.0`.

The `dotnet format` command my GitHub workflow is running looks like the following:
```
dotnet format ${{ github.workspace }}/DotNet.Sdk.Extensions.sln `
--severity info `
--verbosity diagnostic `
--report ${{ env.DOTNET_FORMAT_REPORT_FILEPATH }}
```

This seems related with #1574 .

Hopefully this provides enough information to be able to replicate the issue. Let me know if you need more info.

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.