Skip to content

NUnit2005 was to aggressive comparing 'XXX.Empty' with 'Is.Empty'.#954

Merged
manfred-brands merged 3 commits intomasterfrom
Issue952
Nov 10, 2025
Merged

NUnit2005 was to aggressive comparing 'XXX.Empty' with 'Is.Empty'.#954
manfred-brands merged 3 commits intomasterfrom
Issue952

Conversation

@manfred-brands
Copy link
Member

Fixes #952

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 #952 where the NUnit2005 analyzer was incorrectly suggesting Is.Empty constraint for types that have an Empty member but don't support NUnit's empty assertion (e.g., custom types or enums with an Empty value).

Key Changes:

  • Moved empty candidate detection from code fix helper to diagnostic helper for more accurate analysis
  • Added comprehensive type checking to validate if a type's Empty member is actually compatible with NUnit's Is.Empty constraint
  • Updated code fixes to use diagnostic properties instead of syntax-based detection

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/nunit.analyzers/Helpers/DiagnosticsHelper.cs Added IsEmptyCandidate method with robust type validation to determine if Empty members are compatible with NUnit's empty constraint
src/nunit.analyzers/Constants/AnalyzerPropertyKeys.cs Added IsEmptyCandidate property key for diagnostic communication
src/nunit.analyzers.codefixes/Helpers/CodeFixHelper.cs Removed the less accurate IsEmpty helper method
src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs Updated to use diagnostic properties instead of syntax-based empty detection
src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs Updated to use diagnostic properties instead of syntax-based empty detection
src/nunit.analyzers.tests/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFixTests.cs Added tests for both valid and invalid empty candidate scenarios (custom collection and enum)
src/nunit.analyzers.tests/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFixTests.cs Added test for invalid empty candidate scenario (record struct with Empty property)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

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

Looks good @manfred-brands. I've only two nitpick comments

@manfred-brands manfred-brands merged commit 471af5d into master Nov 10, 2025
6 checks passed
@manfred-brands manfred-brands deleted the Issue952 branch November 10, 2025 23:58
@mikkelbu mikkelbu added this to the Release 4.12 milestone Nov 11, 2025
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.

Code fix for NUnit2005 tries to use Is.Empty constraint on incompatible types.

2 participants