azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Enable DuplicateTypeNameAnalyzer in Azure.ClientSdk.Analyzers for all Azure projects

Open Copilot opened this issue 10 months ago • 0 comments

This PR enables the DuplicateTypeNameAnalyzer and other Azure SDK analyzers to run on all Azure.* projects in the repository, not just shipping client libraries.

Background

A new static analysis rule called DuplicateTypeNameAnalyzer was implemented in the Azure.ClientSdk.Analyzers package to detect duplicate type names across namespaces, which can cause confusion for SDK consumers. However, it was only enabled for IsShippingClientLibrary projects, excluding test projects, sample projects, performance projects, stress projects, and source generators.

Changes Made

1. Extended Analyzer Coverage

Changed the condition from IsShippingClientLibrary to IsClientLibrary in eng/Directory.Build.Common.props:

<!-- Before -->
<EnableClientSdkAnalyzers Condition="'$(IsShippingClientLibrary)' == 'true'">true</EnableClientSdkAnalyzers>

<!-- After -->
<EnableClientSdkAnalyzers Condition="'$(IsClientLibrary)' == 'true'">true</EnableClientSdkAnalyzers>

This enables Azure.ClientSdk.Analyzers for all Azure.* projects including:

  • Production libraries (existing)
  • Test projects (new)
  • Sample projects (new)
  • Performance projects (new)
  • Stress projects (new)
  • Source generation projects (new)

2. Added Targeted Suppressions for Test Projects

Added conditional suppressions for Azure SDK analyzer rules that are less relevant for test projects:

<NoWarn>
  $(NoWarn);
  AZC0100; <!-- ConfigureAwait(false) must be used -->
  AZC0102; <!-- Do not use GetAwaiter().GetResult() -->
  AZC0110; <!-- Asynchronous method async parameter restrictions -->
  AZC0012; <!-- Single word class names -->
  AZC0008; <!-- Client type should have ServiceVersion enum -->
</NoWarn>

These suppressions apply only to test/sample/perf/stress projects where these rules are less critical, while maintaining the full analyzer coverage (including the new DuplicateTypeNameAnalyzer) for production code.

Testing

Verified that:

  • ✅ Production library projects build successfully with full analyzer coverage
  • ✅ Test projects build successfully with appropriate rule suppressions
  • ✅ Sample projects build successfully with analyzer coverage
  • ✅ The DuplicateTypeNameAnalyzer now runs on all Azure projects as requested

The change maintains build stability while successfully extending analyzer coverage to detect duplicate type names across the entire Azure SDK codebase.

Fixes #50608.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jun 13 '25 15:06 Copilot