Skip to content

Add limited support for using var scope = Assert.EnterMultipleScope()#913

Merged
mikkelbu merged 1 commit intomasterfrom
Issue910_using
Sep 27, 2025
Merged

Add limited support for using var scope = Assert.EnterMultipleScope()#913
mikkelbu merged 1 commit intomasterfrom
Issue910_using

Conversation

@manfred-brands
Copy link
Copy Markdown
Member

Fixes #910

It does not detect users calling Dispose() on the declared variable.

I'm a bit reluctant to add this, but we have had 2 independent reports about users using this declaration.

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

Adds limited support for detecting using var scope = Assert.EnterMultipleScope() declarations to prevent false positives in the UseAssertMultiple analyzer. The change addresses user reports about this usage pattern not being recognized.

  • Extends the analyzer to detect local declaration statements with using keyword that initialize variables with Assert.EnterMultipleScope()
  • Adds test coverage for the new declaration pattern and edge cases
  • Updates variable naming in existing tests from PascalCase to camelCase

Reviewed Changes

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

File Description
AssertHelper.cs Adds logic to detect using var scope = Assert.EnterMultipleScope() declarations within the current scope
UseAssertMultipleCodeFixTests.cs Updates variable naming from PascalCase to camelCase for consistency
UseAssertMultipleAnalyzerTests.cs Adds tests for the new declaration pattern and removes conditional compilation guard

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/nunit.analyzers/Helpers/AssertHelper.cs
Comment thread src/nunit.analyzers/Helpers/AssertHelper.cs
Copy link
Copy Markdown
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.

LGTM - sorry that it has taken so long for me to have time to review this.

EDIT: Regarding your concern about adding this, then I think you are correct to add it (and then we will have to see which feedback we receives)

@mikkelbu mikkelbu merged commit 2ae5a44 into master Sep 27, 2025
7 checks passed
@mikkelbu mikkelbu deleted the Issue910_using branch September 27, 2025 12:30
@mikkelbu mikkelbu added this to the Release 4.11 milestone Sep 27, 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.

using declarations not recognized by NUnit2045

3 participants