Skip to content

feat: Add analyzer and codefix for Assert.Multiple => Assert.EnterMultipleScope#878

Merged
mikkelbu merged 4 commits intomasterfrom
feat/async-multiple-to-enter-multiple-scope
Jun 9, 2025
Merged

feat: Add analyzer and codefix for Assert.Multiple => Assert.EnterMultipleScope#878
mikkelbu merged 4 commits intomasterfrom
feat/async-multiple-to-enter-multiple-scope

Conversation

@mikkelbu
Copy link
Copy Markdown
Member

@mikkelbu mikkelbu commented Jun 5, 2025

And similarly for Assert.MultipleAsync => Assert.EnterMultipleScope.

Fixes #866

@mikkelbu mikkelbu force-pushed the feat/async-multiple-to-enter-multiple-scope branch 2 times, most recently from a75029e to 5e9246b Compare June 5, 2025 18:52
…MultipleScope`

And similarly for `Assert.MultipleAsync`
@mikkelbu mikkelbu force-pushed the feat/async-multiple-to-enter-multiple-scope branch from 5e9246b to 32487ac Compare June 5, 2025 19:06
@mikkelbu mikkelbu requested a review from Copilot June 5, 2025 20:16
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 an analyzer and corresponding code fix to replace Assert.Multiple/Assert.MultipleAsync with Assert.EnterMultipleScope, streamlining multiple assertions handling.

  • Added new constants, analyzer, and code fix to perform the replacement.
  • Updated tests and documentation to validate and explain the new pattern.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/nunit.analyzers/UseAssertEnterMultipleScope/UseAssertEnterMultipleScopeConstants.cs Defines constants used by the analyzer and code fix.
src/nunit.analyzers/UseAssertEnterMultipleScope/UseAssertEnterMultipleScopeAnalyzer.cs Implements the analyzer that flags the usage of Assert.Multiple/Assert.MultipleAsync.
src/nunit.analyzers/Constants/AnalyzerIdentifiers.cs Introduces a new analyzer identifier for the Assert.EnterMultipleScope rule.
src/nunit.analyzers.codefixes/UseAssertEnterMultipleScope/UseAssertEnterMultipleScopeCodeFix.cs Provides the code fix that replaces the flagged invocations with a using statement for Assert.EnterMultipleScope.
src/nunit.analyzers.tests/UseAssertEnterMultipleScope/UseAssertEnterMultipleScopeCodeFixTests.cs Contains tests verifying the code fix behavior.
src/nunit.analyzers.tests/UseAssertEnterMultipleScope/UseAssertEnterMultipleScopeAnalyzerTests.cs Contains tests ensuring the analyzer correctly identifies the flagged patterns.
src/nunit.analyzers.sln Updates the solution file to include documentation for the new rule.
documentation/index.md & documentation/NUnit2056.md Update project documentation to include the new analyzer and explain its purpose.

@mikkelbu mikkelbu requested a review from manfred-brands June 5, 2025 20:22
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.

What is there is great, you have forgotten one use case where users passed an async method to Assert.Multiple.
The use case is treated as non-async code, so the issue is flagged, but the code fix generated invalid code as the return type of the test method needs to be async Task.

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 find on using ReplaceNode twice and finding your node using some "SyntaxAnnotation"

I missed last time that FindNearestParentOfType already has a standard equivalent.

One remark about the DescendantNodes being expensive with suggested alternatives.

@mikkelbu
Copy link
Copy Markdown
Member Author

mikkelbu commented Jun 9, 2025

Updated PR with requested changes and also added another test

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.

One nitpick, otherwise nothing else.

@mikkelbu mikkelbu merged commit 52ceb36 into master Jun 9, 2025
6 checks passed
@mikkelbu mikkelbu deleted the feat/async-multiple-to-enter-multiple-scope branch June 9, 2025 11:25
@mikkelbu mikkelbu added this to the Release 4.9 milestone Jun 9, 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.

When Assert.Multiple is found, should suggest to convert to Assert.EnterMultipleScope

3 participants