Skip to content

Conversation

@manfred-brands
Copy link
Contributor

Fixes #51716

  • Added unit test with two extension blocks. Ensuring it fails in existing implementation.
  • Add IsExtension for INamedTypeSymbol using LightupHelpers.
  • Ignore extension blocks in IdentifiersShouldDifferByMoreThanCaseAnalyzer

@manfred-brands manfred-brands requested a review from a team as a code owner November 21, 2025 01:22
Copilot AI review requested due to automatic review settings November 21, 2025 01:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #51716 by preventing the CA1708 analyzer from flagging naming conflicts within C# extension blocks. Extension blocks are a new C# 14 language feature that should be excluded from the identifier case-sensitivity check.

Key Changes:

  • Added IsExtension property accessor for INamedTypeSymbol via lightup helpers
  • Modified the analyzer to skip extension blocks when checking for case-only identifier differences
  • Added unit test validating that extension blocks with similar names don't trigger warnings

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
IdentifiersShouldDifferByMoreThanCaseTests.cs Added test case with two extension blocks to verify they are excluded from CA1708 checks
ISymbolExtensions.cs Added IsExtension helper method to check if a symbol is an extension block
INamedTypeSymbolExtensions.cs Implemented IsExtension property accessor using lightup helpers for forward compatibility
IdentifiersShouldDifferByMoreThanCase.cs Updated analyzer logic to skip extension blocks during name checking
Comments suppressed due to low confidence (1)

src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/IdentifiersShouldDifferByMoreThanCaseTests.cs:1

  • The test validates that no CA1708 warnings are raised, but doesn't verify that the analyzer still works correctly for non-extension members. Consider adding a case where ExtensionString, CreateExtension, or IsExtensionString have case-only variations (e.g., extensionString, createExtension) outside of extension blocks to ensure the analyzer still catches those conflicts.
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the MIT license.  See License.txt in the project root for license information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CA1708 is incorrectly reported for extension members

1 participant