dotnet / format

Home for the dotnet-format command
MIT License
1.91k stars 172 forks source link

CS0534 validation adding wrong code. #2195

Open InsomniumBR opened 1 month ago

InsomniumBR commented 1 month ago

Hello everyone,

I am experiencing one issue and I could not find a workaround to that so far. I am using dotnet format with Husky to keep our code consistent.

Dotnet runtime: 8.0.5 dotnet-format: 5.1.250801 husky: 0.5.4

I have this class below which I use to mock an HttpReponseData:

    public class DocumentHttpResponseData : HttpResponseData
    {
        private Stream _body = new MemoryStream();

        public DocumentHttpResponseData(FunctionContext functionContext) : base(functionContext)
        {
        }

        public override HttpStatusCode StatusCode { get; set; }
        public override HttpHeadersCollection Headers { get; set; } = new HttpHeadersCollection();

        public override Stream Body { get => _body; set => throw new System.NotImplementedException(); }
        public override HttpCookies Cookies { get; }
    }

When I run dotnet-format using Husky, I got this rule being triggered:

error CS0102: The type 'DocumentHttpResponseData' already contains a definition for 'Body'

This is the resulting code:

image

I have tried to add to .editorconfig this configuration to try to avoid that:

dotnet_diagnostic.CS0534.severity = none

But I have had no luck so far.

Any insights?

Thanks in advance

InsomniumBR commented 1 month ago

I think that I found today a workaround for that. When I add the namespace to the Stream object, it stops to change it.

New code:

image

Maybe that gives you more insights on what's going on there.