format
format copied to clipboard
Legitimate whitespace error triggering other unrelated invalid whitespace errors in same file
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.
:memo: If this issue can be reproduced in Visual Studio using IDE0055 and/or the Format Document operation, it would need to be moved to dotnet/roslyn for further investigation.