Skip to content

[dotnet format] EnforceCodeStyleInBuild behaves weird with NUnit Roslyn suppressors #44867

@BinaryTENSHi

Description

@BinaryTENSHi

Describe the bug

The NUnit.Analyzers project provides a suppressor that suppresses the CS8616 error when a non-nullable field is being initialized via a SetUp or OneTimeSetUp method. See: https://docs.nunit.org/articles/nunit-analyzers/NUnit3002.html

Having EnforceCodeStyleInBuild set to true seems to not run or ignore this suppressor and dotnet format --verify-no-changes errors out with a CS8616 error.

To Reproduce

I have created a minimal reproducible example here: https://github.com/BinaryTENSHi/dotnet-format-nunit-suppress

  1. Clone the repository
  2. Run dotnet format --verify-no-changes

Further technical details

dotnet --info

.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.3068a692
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/user/.dotnet/sdk/9.0.100/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  6.0.428 [/home/user/.dotnet/sdk]
  8.0.403 [/home/user/.dotnet/sdk]
  9.0.100 [/home/user/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.36 [/home/user/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.5 [/home/user/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.8 [/home/user/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.10 [/home/user/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [/home/user/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [/home/user/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.5 [/home/user/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.8 [/home/user/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.10 [/home/user/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [/home/user/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/home/user/.dotnet/]

global.json file:
  /home/user/work/dotnet-format-nunit-suppress/global.json

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions