dotnet / dotnet/format

Legitimate whitespace error triggering other unrelated invalid whitespace errors in same file

Open
#2,045 1 comment 0 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

I've come across a strange behavior with `dotnet format --verify-no-changes` that I can't make sense of. I've created a minimal example at https://github.com/Inirit/dotnet-format-bug-repro/tree/main and I've explained the setup below:

There's four source files: NoRepro1.cs, NoRepro2.cs, NoRepro3.cs, and Repro.cs. All four files have a single class with a single simple method with slight differences between the method bodies.

- The method body in NoRepro1.cs has a single-line comment along with a call to Console.WriteLine. `dotnet format --verify-no-changes` detects no errors in this file as expected.

- The method body in NoRepro2.cs has the same call to Console.WriteLine but removes the single-line comment and adds a variable declaration. `dotnet format --verify-no-changes` again detects no errors in this file as expected.

- The method body in NoRepro3.cs is almost exactly the same as in NoRepro2.cs but the space between the "=" and "0" for the variable declaration is removed. `dotnet format --verify-no-changes` detects a single whitespace error in this file as expected.

- Repro.cs combines the method bodies of the other source files by including the single-line comment, the call to Console.WriteLine, and the variable declaration with the intentional whitespace error. But instead of reporting a single error for this file, `dotnet format --verify-no-changes` reports three errors. One is the expected error (same as NoRepro3.cs) but the other two errors are not expected and suggest fixes that don't really make sense (adding blank new lines around the comment, each with two tabs). The errors around this comment line only trigger when the file also has the other valid whitespace error in it, NoRepro1.cs has the same comment without the variable declaration line and no errors are reported for it.

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.