Skip to content

feat: Add analyzer and codefix for is operator into Is.InstanceOf#875

Merged
mikkelbu merged 2 commits intomasterfrom
feat/add-isinstanceof-analyzer-codefix
Jun 2, 2025
Merged

feat: Add analyzer and codefix for is operator into Is.InstanceOf#875
mikkelbu merged 2 commits intomasterfrom
feat/add-isinstanceof-analyzer-codefix

Conversation

@mikkelbu
Copy link
Copy Markdown
Member

@mikkelbu mikkelbu commented Jun 1, 2025

Fixes #765

@mikkelbu mikkelbu added this to the Release 4.9 milestone Jun 1, 2025
@mikkelbu mikkelbu force-pushed the feat/add-isinstanceof-analyzer-codefix branch 2 times, most recently from f749b40 to d74c602 Compare June 1, 2025 21:13
@mikkelbu mikkelbu requested a review from Copilot June 1, 2025 21:13
Copy link
Copy Markdown
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 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 InstanceOfAnalyzer and InstanceOfCodeFix to identify and fix is operator 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";

Comment thread documentation/index.md Outdated
Comment thread src/nunit.analyzers.codefixes/InstanceOf/InstanceOfCodeFix.cs
Comment thread src/nunit.analyzers.codefixes/InstanceOf/InstanceOfCodeFix.cs
@mikkelbu mikkelbu force-pushed the feat/add-isinstanceof-analyzer-codefix branch from d74c602 to d5793f4 Compare June 1, 2025 21:23
Copy link
Copy Markdown
Member

@manfred-brands manfred-brands left a comment

Choose a reason for hiding this comment

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

Nice. Only a few nitpicks.

Comment thread src/nunit.analyzers.tests/InstanceOf/InstanceOfTests.cs
Comment thread src/nunit.analyzers.tests/InstanceOf/InstanceOfCodeFixTests.cs Outdated
Comment thread src/nunit.analyzers.tests/InstanceOf/InstanceOfCodeFixTests.cs Outdated
Comment thread documentation/NUnit2055.md Outdated
@mikkelbu mikkelbu merged commit 7bf72b6 into master Jun 2, 2025
6 checks passed
@mikkelbu mikkelbu deleted the feat/add-isinstanceof-analyzer-codefix branch June 2, 2025 09:13
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.

Add Rule for converting is T into Is.InstanceOf<T>()

3 participants