Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
edyoung opened this issue Nov 20, 2024 · 2 comments · Fixed by #1392
Closed

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

edyoung opened this issue Nov 20, 2024 · 2 comments · Fixed by #1392
Milestone

Comments

@edyoung
Copy link

edyoung commented Nov 20, 2024

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 } 
        };     
    }

    
}

@belav
Copy link
Owner

belav commented Nov 22, 2024

The syntax tree validation logic doesn't account for the edge case I fixed in 0.30.0 where the trailing comma needs to be added before the trailing comment. I'm hoping this will be a quick fix that I can get out today, but if not it is safe to ignore. It'll only fail the validation when it first adds the comma.

@belav belav added this to the 0.30.2 milestone Nov 22, 2024
belav added a commit that referenced this issue Nov 22, 2024
…trailing comma before a trailing comment

closes #1388
@belav belav closed this as completed in 576a75b Nov 22, 2024
@edyoung
Copy link
Author

edyoung commented Nov 22, 2024

Thanks a lot!

pisolofin pushed a commit to pisolofin/csharpier-editorconfig that referenced this issue Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants