Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nunit1032 - consider dispose of a type having explicit interface implementation #710

Merged

Conversation

matode
Copy link
Contributor

@matode matode commented Mar 26, 2024

In case a class does inherit from IDisposable, but Dispose is implemented with explicit interface implementation (void IDisposable.Dispose()), then the Dispose call in TearDown method is not considered by NUnit1032.

This change considers casting of given type to IDisposable and doesn't report a finding in such case

@matode
Copy link
Contributor Author

matode commented Mar 26, 2024

@dotnet-policy-service agree

Copy link
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. I considering if we could make the code in GetIdentifier more general to e.g. also support cases such like

private DummyExplicitDisposable field2;
...
[OneTimeTearDown]
public void Dispose()
{
    IDisposable x = field2;
    x.Dispose();
}

But I think this is already an improvement, and then we can always improve on this later on

@mikkelbu
Copy link
Member

Thanks for the contribution @matode. I'll merge it now

@mikkelbu mikkelbu merged commit e52e3a1 into nunit:master Mar 27, 2024
6 checks passed
@mikkelbu mikkelbu added this to the Release 4.2 milestone Mar 27, 2024
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.

None yet

2 participants