dotnet / format

Home for the dotnet-format command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] `dotnet-format --check` throws error when having `required` keyword followed by any enum

gtamvakas opened this issue · comments

Versions:

  • dotnet-format 5.1.250801
  • .NET 7

Problem:

Running dotnet-format --check throws the error error WHITESPACE: Fix whitespace formatting. Delete [number] characters. when there is a property that is an enum and it is preceded by the required keyword. Removing the required keyword leads to no errors.

This is only happening with a required enum and it is not happening with any other types, e.g int, string, custom or built-in classes, etc. Also note that it is happening with any enum, whether it is user-defined or a built-in, e.g HttpStatusCode.

Steps to reproduce:

  • Create a new project
  • Create a simple enum:
    internal enum Foo
    {
        Bar = 1,
        Baz = 2
    }
  • Create a class:
    internal class TestClass
    {
        internal required Foo MyEnum { get; set; }
    }
  • Run dotnet-format --check

This will lead to the error TestClass.cs(6,1): error WHITESPACE: Fix whitespace formatting. Delete 4 characters. which asks me to delete the spaces before the last } which doesn't make sense because it will lead to wrong formatting.

Removing the required keyword makes the formatter complete without errors.

Hi @gtamvakas, dotnet-format 5.x only supports up to the .NET 5 SDK. Starting in .NET 6 dotnet-format ships with the SDK and can be invoked from the CLI as dotnet format. Please see this announcement which lists how the various options have changed - #1268.

I am closing this out, but please open new issues if you run into any trouble.