roslynator
roslynator copied to clipboard
RCS0053 - does some strange formatting
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 formatis run more than once, it seems to indentDiagnosticsin example 2 more than once.
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.
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
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.
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)
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
}
});
}
}
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.
Hi @prezaei,
I'll try to take a look at this issue when possible.