-
Notifications
You must be signed in to change notification settings - Fork 34
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
DisposableFieldsSuppressor and Analyzer #576
DisposableFieldsSuppressor and Analyzer #576
Conversation
471ce36
to
d67a14d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have to review most of DisposeFieldsInTearDownAnalyzer
(I think I've reviewed one quarter of it). I hope I've time to do it tomorrow when my head is not overloaded.
So far it looks great 👍
src/nunit.analyzers.tests/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @manfred-brands. I only have some minor comments, questions, suggestions
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/nunit.analyzers/DisposeFieldsInTearDown/DisposeFieldsInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
d67a14d
to
92687c5
Compare
Looks good @manfred-brands. I'm happy to merge this when you are |
I'll do some test on existing code bases to see if it picks things up as expected. |
I get some false positives on writers that are |
TODO: Items found during letting it loose on a big project
|
@mikkelbu Can you please re-review. I made several changes after letting it loose on our main project. I also found two other bugs in the current version and created two separate small PRs for them. |
I've reviewed the other PRs, and I'll take a look at this tonight (as it requires some more time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the review one commit at a time and you corrected the few minor nitpicks I found in subsequent commits, so great work 👍. So I only have one typo left.
...alyzers/DisposeFieldsAndPropertiesInTearDown/DisposeFieldsAndPropertiesInTearDownAnalyzer.cs
Outdated
Show resolved
Hide resolved
* await * ConfigureAwait * try * finally * Close is recognized as Dispose method
* Ignore classes that are not a TestFixture * Ignore some types that don't need Disposing, e.g. Task * Only check fields assigned from constructors and methods, not from copy and other expressions.
Add support for Release(field) and allow configuring extra release methods.
Previously it created several and then merged them.
0e49e22
to
9fee186
Compare
Thanks @mikkelbu for your reviews. |
Fixes #568
There is a new
DiagnosticSuppressor
that suppresses the CA1001 error if the class is aTestFixture
.There is also a new
DiagnosticsAnalyzer
which analyzes fields.IDisposable
field is set in theOneTimeSetUp
method it is onlyDisposed
in theOneTimeTearDown
method.IDisposable
fields must be disposed inTearDown
method.IAsyncDisposable
Disposal detection is limited, but I think probably sufficient for a
TearDown
method.As long as
field.Dispose()
orfield?.Dispose()
is called, it is deemed disposed.It could be that the field is conditionally assigned and therefore conditionally Disposed.
It is way beyond the scope to find out that the conditions are different.