dotnet / dotnet/format

Tool should return error exit code if it fails to apply fixes and report the relevant warnings

Open
#1,508 1 comment 5 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

Repro:

`Program.cs`:
```C#
TestMethod(0);

void TestMethod(int unused)
{
}
```

`.editorconfig`:
```
[*cs]
# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning
```

```console
> dotnet format
Unable to fix IDE0060. No associated code fix found.
> dotnet format --verify-no-changes
...\Program.cs(6,21): warning IDE0060: Remove unused parameter 'unused' [...csproj]

```

I definitely understand that there are warnings which can't be fixed automatically - like removing parameters to a method. But in that case I would expect the tool to report the actual warning. Just saying the it can't fix IDE0060 doesn't help ... where? Also note that it will say this even if there are 100s warnings like that, so there's no indication of how "bad" it is.

I would also expect the tool to report failure exit code if this happens. Mainly since it should match what it does when run with `--verify-no-changes`.

Scenario:
In the CI, we run `dotnet format --verify-no-changes` to enforce the rules. The guide is: "If this fails, run `dotnet format` locally before PR".
But with the above if I run `dotnet format` it doesn't fail and it only says that it could not fix something but doesn't say what, so people tend to simply ignore that. And then it fails in CI.

If not by default, there should at least be some command line option to get a better behavior. I do know that it's possible to get the warnings with `-v d`, but that produces lot of additional output, which again makes it confusing.

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.