Open
Description
Describe the bug
When dealing with ? :
C# expressions, dotnet format
falsely reports whitespace errors when run with --verify-no-changes
.
To Reproduce
git clone https://github.com/AArnott/vs-threading
cd vs-threading
git checkout 52a1e174661987de31061a47df64076f11cb8366
dotnet format --verify-no-changes
Produces this output:
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs(256,60): error WHITESPACE: Fix whitespace formatting. Delete 1 characters. [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/RarelyRemoveItemSet`1.cs(217,61): error WHITESPACE: Fix whitespace formatting. Delete 1 characters. [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs(256,59): warning SA1011: Closing square bracket should be followed by a space [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/RarelyRemoveItemSet`1.cs(217,60): warning SA1011: Closing square bracket should be followed by a space [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs(256,60): warning SA1003: Operator '?' should be preceded by whitespace. [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/RarelyRemoveItemSet`1.cs(217,61): warning SA1003: Operator '?' should be preceded by whitespace. [/workspaces/vs-threading/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj]
The lines in question are:
this.currentIndex = this.enumeratedValue is T[] ? IndexBeforeFirstArrayElement : IndexBeforeSingleElement;
and
this.currentIndex = this.enumeratedValue is T?[] ? IndexBeforeFirstArrayElement : IndexBeforeSingleElement;
But these lines are well formatted. And in fact running dotnet format
without the --verify-no-changes
switch applies no change to the syntax.
Further technical details
dotnet --info
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6c33ef20
Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /root/.dotnet/sdk/8.0.100/
.NET workloads installed:
Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.
Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71
.NET SDKs installed:
7.0.401 [/root/.dotnet/sdk]
8.0.100 [/root/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.11 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.25 [/root/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.11 [/root/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [/root/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/root/.dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/root/.dotnet]
global.json file:
/workspaces/vs-threading/global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download