NUnit2005 was to aggressive comparing 'XXX.Empty' with 'Is.Empty'.#954
Merged
manfred-brands merged 3 commits intomasterfrom Nov 10, 2025
Merged
NUnit2005 was to aggressive comparing 'XXX.Empty' with 'Is.Empty'.#954manfred-brands merged 3 commits intomasterfrom
manfred-brands merged 3 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
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
Emptymember is actually compatible with NUnit'sIs.Emptyconstraint - 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.
mikkelbu
approved these changes
Nov 10, 2025
Member
mikkelbu
left a comment
There was a problem hiding this comment.
Looks good @manfred-brands. I've only two nitpick comments
...nunit.analyzers.tests/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFixTests.cs
Outdated
Show resolved
Hide resolved
...nunit.analyzers.tests/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFixTests.cs
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #952