Skip to content

respect attribute namespace during migration#5066

Merged
thomhurst merged 3 commits intothomhurst:mainfrom
SimonCropp:NUnit_Ignore_From_Different_Namespace_Not_Converted
Mar 3, 2026
Merged

respect attribute namespace during migration#5066
thomhurst merged 3 commits intothomhurst:mainfrom
SimonCropp:NUnit_Ignore_From_Different_Namespace_Not_Converted

Conversation

@SimonCropp
Copy link
Contributor

No description provided.

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Code Review: respect attribute namespace during migration

Summary: This PR fixes a real and non-obvious bug — the migration analyzers were matching attributes by name only, so a user-defined [MyCompany.Attributes.Ignore] would get incorrectly migrated as if it were [NUnit.Framework.Ignore]. Using the semantic model to verify the containing namespace before converting is the right approach.


Design

The chosen architecture is clean:

  • A single abstract IsFrameworkNamespace(string? ns) to keep framework-specific knowledge in each concrete analyzer
  • A concrete IsFrameworkAttribute(AttributeSyntax node) in the base class handles the semantic lookup and composes the null-fallback logic centrally
  • The guard is placed before both the removal check and the conversion check, so the fix is applied consistently to both paths

This is exactly the right level of abstraction. No concerns here.


One Minor Observation

IsFrameworkNamespace has a string? parameter, but the base-class caller already guards the null case:

var ns = symbol?.ContainingType?.ContainingNamespace?.ToDisplayString();

if (ns == null)
    return true; // If we can't resolve, assume framework (preserves existing behavior)

return IsFrameworkNamespace(ns); // ns is guaranteed non-null here

All three implementations then re-check ns != null defensively, which is harmless but redundant. The parameter could be string (non-nullable) since the abstract method is never called with null. This is a very minor point and either style is acceptable — nullable is arguably safer as a defensive API surface.


Fallback Behavior

Returning true (treat as framework attribute) when the symbol can't be resolved is the right conservative default. It preserves existing behavior for edge cases where semantic information isn't available, avoiding false negatives in the migration tool.


Test Coverage

The parameterized tests are well-chosen — they enumerate the most common attribute names that could realistically collide with user-defined types, and verify the full round-trip through the code fixer. Coverage spans all three frameworks. Good work.


Verdict: This is a correct, well-structured fix with solid tests. The only observation above is cosmetic and doesn't warrant a change. Approving.

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Code Review: respect attribute namespace during migration

Summary: This PR fixes a real and non-obvious bug — the migration analyzers were matching attributes by name only, so a user-defined [MyCompany.Attributes.Ignore] would get incorrectly migrated as if it were [NUnit.Framework.Ignore]. Using the semantic model to verify the containing namespace before converting is the right approach.


Design

The chosen architecture is clean:

  • A single abstract IsFrameworkNamespace(string? ns) keeps framework-specific knowledge in each concrete analyzer
  • A concrete IsFrameworkAttribute(AttributeSyntax node) in the base class handles the semantic lookup and composes the null-fallback logic centrally
  • The guard is placed before both the removal check and the conversion check, so the fix is applied consistently to both paths

This is exactly the right level of abstraction. No concerns here.


One Minor Observation

IsFrameworkNamespace has a string? parameter, but the base-class caller already guards the null case:

var ns = symbol?.ContainingType?.ContainingNamespace?.ToDisplayString();

if (ns == null)
    return true; // If we can't resolve, assume framework (preserves existing behavior)

return IsFrameworkNamespace(ns); // ns is guaranteed non-null here

All three implementations then re-check ns != null defensively, which is harmless but redundant. The parameter could be string (non-nullable) since the abstract method is never called with null. Minor point — either style is acceptable.


Fallback Behavior

Returning true (treat as framework attribute) when the symbol can't be resolved is the right conservative default. It preserves existing behavior for edge cases where semantic information isn't available, avoiding false negatives in the migration tool.


Test Coverage

The parameterized tests are well-chosen — they enumerate the most common attribute names that could realistically collide with user-defined types, and verify the full round-trip through the code fixer. Coverage spans all three frameworks (NUnit, MSTest, xUnit). Good work.


Verdict: Correct, well-structured fix with solid tests. Approved.

@thomhurst thomhurst enabled auto-merge (squash) March 3, 2026 12:11
@thomhurst
Copy link
Owner

Thanks!

@thomhurst thomhurst merged commit 06b9ea9 into thomhurst:main Mar 3, 2026
8 of 11 checks passed
@SimonCropp SimonCropp deleted the NUnit_Ignore_From_Different_Namespace_Not_Converted branch March 3, 2026 21:49
@claude claude bot mentioned this pull request Mar 3, 2026
1 task
This was referenced Mar 14, 2026
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