Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Inirit opened this issue Dec 8, 2023 · 1 comment

Comments

@Inirit
Copy link

Inirit commented Dec 8, 2023

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.

@sharwell
Copy link
Member

sharwell commented Feb 15, 2024

📝 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants