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

[Azure.ClientSdk.Analyzers] Refine AZC0030 #9961

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jorgerangel-msft
Copy link
Member

@jorgerangel-msft jorgerangel-msft commented Mar 3, 2025

This PR introduces fixes for these items:

sdk-for-net test pr: Azure/azure-sdk-for-net#48597

@jorgerangel-msft jorgerangel-msft changed the title .net: refine Refine AZC0030 .net: Refine AZC0030 Mar 3, 2025
@jorgerangel-msft jorgerangel-msft force-pushed the refine-AZC0030 branch 2 times, most recently from ce95f75 to a9926ed Compare March 5, 2025 23:55
private const string JsonElement = "JsonElement";
private static readonly string[] suffixes = new string[] { OptionsSuffix };

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Descriptors.AZC0030); } }
Copy link
Member Author

@jorgerangel-msft jorgerangel-msft Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we want a different behavior for when a model is suffixed with "Options", I've split that functionality into this new class which still shares the original diagnostic ID with GeneralSuffixAnalyzer. My main motivation was to reduce the blast radius of this change, in the case that users have suppressed the original diagnostic ID. If we feel like these changes warrant a new ID, it should be setup to easily do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking.

@jorgerangel-msft jorgerangel-msft changed the title .net: Refine AZC0030 [Azure.ClientSdk.Analyzers] Refine AZC0030 Mar 6, 2025
@jorgerangel-msft jorgerangel-msft marked this pull request as ready for review March 6, 2025 22:50
private const string JsonElement = "JsonElement";
private static readonly string[] suffixes = new string[] { OptionsSuffix };

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Descriptors.AZC0030); } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking.

private const string JsonElement = "JsonElement";
private static readonly string[] suffixes = new string[] { OptionsSuffix };

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Descriptors.AZC0030); } }
Copy link
Member

@jsquire jsquire Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern will allocate each time the property is called. Since the underlying array is immutable, we should be able to share the same instance.

Suggested change
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Descriptors.AZC0030); } }
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
ImmutableArray.Create(Descriptors.AZC0030);

Comment on lines +58 to +64
if ($"{fullNamespace}".Equals(AzureResourceManagerNamespaceName)
|| $"{fullNamespace}".StartsWith($"{AzureResourceManagerNamespaceName}."))
{
return true;
}

return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($"{fullNamespace}".Equals(AzureResourceManagerNamespaceName)
|| $"{fullNamespace}".StartsWith($"{AzureResourceManagerNamespaceName}."))
{
return true;
}
return false;
return ($"{fullNamespace}".Equals(AzureResourceManagerNamespaceName)
|| $"{fullNamespace}".StartsWith($"{AzureResourceManagerNamespaceName}."));

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 this pull request may close these issues.

2 participants