roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

RCS0053 - does some strange formatting

Open prezaei opened this issue 1 year ago • 4 comments

Product and Version Used: NuGet package - 4.12.4

Steps to Reproduce: Enable the rule

Example 1

Actual Behavior:

    private static readonly FrozenSet<string?> SomeThing =
        SomeFunction
            .Concat(
                [
                    // some comment
                    null,
                    ])
            .ToFrozenSet();

Expected Behavior:

    private static readonly FrozenSet<string?> SomeThing =
        SomeFunction
            .Concat(
            [
                // some comment
                null,
            ])
            .ToFrozenSet();

Example 2

Actual Behavior:

        return new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = clientId,
                ExcludeWorkloadIdentityCredential = true,
                Diagnostics =
                        {
                            IsAccountIdentifierLoggingEnabled = diagnosticsEnabled,
                            IsDistributedTracingEnabled = diagnosticsEnabled,
                            IsLoggingEnabled = diagnosticsEnabled
                        }
            });

Expected Behavior:

        return new DefaultAzureCredential(new DefaultAzureCredentialOptions
        {
            ManagedIdentityClientId = clientId,
            ExcludeWorkloadIdentityCredential = true,
            Diagnostics =
            {
                IsAccountIdentifierLoggingEnabled = diagnosticsEnabled,
                IsDistributedTracingEnabled = diagnosticsEnabled,
                IsLoggingEnabled = diagnosticsEnabled
            }
        });

Issue:

So, what is wrong with the above?

  • In example 1 open and end brackets have different indentations
  • It adds an extra indentation level when one is not needed (see the outer layer in example 2). This conflicts with the default formatter in VS as well.
  • If dotnet format is run more than once, it seems to indent Diagnostics in example 2 more than once.

prezaei avatar Aug 10 '24 23:08 prezaei

Hi,

You posted a code that shows a state after the fix has been applied. Can you also post a code that show a state before the fix has been applied so I'm able to reproduce it? Thanks.

josefpihrt avatar Aug 12 '24 21:08 josefpihrt

Hi,

You posted a code that shows a state after the fix has been applied. Can you also post a code that show a state before the fix has been applied so I'm able to reproduce it? Thanks.

Thank you. The before state is what I have as the expected state. Both expected and before so it should not have made a change. Thanks

prezaei avatar Aug 13 '24 02:08 prezaei

I was able to reproduce first one. Regarding the second one, this is what I get when applying a code fix:

        return new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = clientId,
                ExcludeWorkloadIdentityCredential = true,
                Diagnostics =
                {
                    IsAccountIdentifierLoggingEnabled = diagnosticsEnabled,
                    IsDistributedTracingEnabled = diagnosticsEnabled,
                    IsLoggingEnabled = diagnosticsEnabled
                }
            });

which seems fine.

Could you sent a second one as an entire file (including containing class etc.). Also could you check whitespace if there isn't mix of spaces vs. tabs.

josefpihrt avatar Aug 13 '24 20:08 josefpihrt

I was able to reproduce first one. Regarding the second one, this is what I get when applying a code fix:

        return new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = clientId,
                ExcludeWorkloadIdentityCredential = true,
                Diagnostics =
                {
                    IsAccountIdentifierLoggingEnabled = diagnosticsEnabled,
                    IsDistributedTracingEnabled = diagnosticsEnabled,
                    IsLoggingEnabled = diagnosticsEnabled
                }
            });

which seems fine.

Could you sent a second one as an entire file (including containing class etc.). Also could you check whitespace if there isn't mix of spaces vs. tabs.

Thanks. There are 2 issues here in this particular example. first one is visible in your output: (this goes against what the default .NET Formatter in Visual Studio does)

image

The second issue can only be reproduced if dotnet format is run more than once. Each time, it will move the brackets for Diagnostics one level deeper.

Anyway, here is the full file:

using Azure.Core;
using Azure.Identity;
using Microsoft.Extensions.Configuration;

namespace SomeNamespace.Auth;
public static class ConfigurationExtensions
{
    public static TokenCredential CreateRegionalServiceCredential(this IConfiguration configuration)
    {
        var clientId = configuration["ServiceCredential:PodIdentity:ClientId"];
        var diagnosticsEnabled = configuration.GetValue("ServiceCredential:DiagnosticsEnabled", false);

        return new DefaultAzureCredential(new DefaultAzureCredentialOptions
        {
            ManagedIdentityClientId = clientId,
            ExcludeWorkloadIdentityCredential = true,
            Diagnostics =
            {
                IsAccountIdentifierLoggingEnabled = diagnosticsEnabled,
                IsDistributedTracingEnabled = diagnosticsEnabled,
                IsLoggingEnabled = diagnosticsEnabled
            }
        });
    }
}

prezaei avatar Aug 14 '24 05:08 prezaei

Hi @josefpihrt , I am sorry for pinging on this. do you happen to have some solution for this? This will be a HUGE help to us. So thank you.

prezaei avatar Sep 01 '24 15:09 prezaei

Hi @prezaei,

I'll try to take a look at this issue when possible.

josefpihrt avatar Sep 01 '24 20:09 josefpihrt