feat: Add analyzer and codefix for is operator into Is.InstanceOf#875
Merged
feat: Add analyzer and codefix for is operator into Is.InstanceOf#875
is operator into Is.InstanceOf#875Conversation
f749b40 to
d74c602
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new analyzer and accompanying code fix to detect and replace is T expressions inside Assert.That calls with the more expressive Is.InstanceOf<T> (or Is.Not.InstanceOf<T>) constraint.
- Adds
InstanceOfAnalyzerandInstanceOfCodeFixto identify and fixisoperator usage in assertions - Implements tests for both analyzer (
InstanceOfTests) and code fix (InstanceOfCodeFixTests) - Updates solution, constants, and documentation to register and describe rule
NUnit2055
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/nunit.analyzers/InstanceOf/InstanceOfConstants.cs | Defines titles, messages, and descriptions for the new rule |
| src/nunit.analyzers/InstanceOf/InstanceOfAnalyzer.cs | Implements diagnostic to catch is T expressions in Assert |
| src/nunit.analyzers/Constants/AnalyzerIdentifiers.cs | Registers new identifier InstanceOf (NUnit2055) |
| src/nunit.analyzers.tests/InstanceOf/InstanceOfTests.cs | Analyzer unit tests |
| src/nunit.analyzers.tests/InstanceOf/InstanceOfCodeFixTests.cs | Code-fix unit tests |
| src/nunit.analyzers.sln | Adds documentation link for NUnit2055 |
| src/nunit.analyzers.codefixes/InstanceOf/InstanceOfCodeFix.cs | Provides code fix to rewrite to Is.InstanceOf<T>() |
| documentation/index.md | Adds table entry for new rule |
| documentation/NUnit2055.md | Full documentation for new rule NUnit2055 |
Comments suppressed due to low confidence (1)
src/nunit.analyzers.codefixes/InstanceOf/InstanceOfCodeFix.cs:18
- [nitpick] Consider renaming this to include the generic parameter (e.g.
"Use Is.InstanceOf<T> constraint") so the fix title more precisely reflects the change.
internal const string UseInstanceOfConstraint = "Use Is.InstanceOf constraint";
d74c602 to
d5793f4
Compare
manfred-brands
approved these changes
Jun 2, 2025
Member
manfred-brands
left a comment
There was a problem hiding this comment.
Nice. Only a few nitpicks.
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 #765