belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.41k stars 98 forks source link

Failed syntax tree validation reported, but input and output code look OK #1388

Open edyoung opened 2 days ago

edyoung commented 2 days ago

Csharpier version 0.30.1

Input:

using System.Text.Json;

namespace Microsoft.Azure.HybridCompute.Shared.DataModel.Entities.NetworkSecurityPerimeter;

public class NSPValidationData
{
    public NSPValidationData()
    {    
        var accessRulesResponsePayload = new Dictionary<string, List<int>? >
        {
            { "value", accessRulesResponseModel } // NSP data plane library expects this format
        };     
    }

}

Command line Output:

> dotnet csharpier test.cs
Error ./test.cs - Failed syntax tree validation.
  ----------------------------- Original: Around Line 10 -----------------------------
          var accessRulesResponsePayload = new Dictionary<string, List<int>? >
          {
              { "value", accessRulesResponseModel } // NSP data plane library expects this format
          };
      }

  }
  ----------------------------- Formatted: Around Line 0 -----------------------------
  using System.Text.Json;

  namespace Microsoft.Azure.HybridCompute.Shared.DataModel.Entities.NetworkSecurityPerimeter;

  public class NSPValidationData
  {
      public NSPValidationData()
      {
Formatted 1 files in 213ms.

file output

using System.Text.Json;

namespace Microsoft.Azure.HybridCompute.Shared.DataModel.Entities.NetworkSecurityPerimeter;

public class NSPValidationData
{
    public NSPValidationData()
    {
        var accessRulesResponsePayload = new Dictionary<string, List<int>?>
        {
            { "value", accessRulesResponseModel }, // NSP data plane library expects this format
        };
    }
}

Expected behavior: There doesn't seem to be an issue with the syntax tree, so I don't expect to see an error reported.

If I remove the comment, and change the input to the file below, I don't see any error.

using System.Text.Json;

namespace Microsoft.Azure.HybridCompute.Shared.DataModel.Entities.NetworkSecurityPerimeter;

public class NSPValidationData
{
    public NSPValidationData()
    {    
        var accessRulesResponsePayload = new Dictionary<string, List<int>? >
        {
            { "value", accessRulesResponseModel } 
        };     
    }

}