Skip to content

AArnott/IDisposableAnalyzers

 
 

Repository files navigation

IDisposableAnalyzers

Roslyn analyzers for IDisposable

License Gitter Build status NuGet

animation

  • 1.x versions are for Visual Studio 2015.
  • 2.x versions are for Visual Studio 2017.
IDISP001 Dispose created.
IDISP002 Dispose member.
IDISP003 Dispose previous before re-assigning.
IDISP004 Don't ignore return value of type IDisposable.
IDISP005 Return type should indicate that the value should be disposed.
IDISP006 Implement IDisposable.
IDISP007 Don't dispose injected.
IDISP008 Don't assign member with injected and created disposables.
IDISP009 Add IDisposable interface.
IDISP010 Call base.Dispose(disposing)
IDISP011 Don't return disposed instance.
IDISP012 Property should not return created disposable.
IDISP013 Await in using.
IDISP014 Use a single instance of HttpClient.
IDISP015 Member should not return created and cached instance.
IDISP016 Don't use disposed instance.
IDISP017 Prefer using.
IDISP018 Call SuppressFinalize.
IDISP019 Call SuppressFinalize.
IDISP020 Call SuppressFinalize with this.
IDISP021 Call this.Dispose(true).
IDISP022 Call this.Dispose(false).
IDISP023 Don't use reference types in finalizer context.
SemanticModelCacheAnalyzer Controls if Semantic models should be cached for syntax trees.

Using IDisposableAnalyzers

The preferable way to use the analyzers is to add the nuget package IDisposableAnalyzers to the project(s).

The severity of individual rules may be configured using rule set files in Visual Studio 2015.

Installation

IDisposableAnalyzers can be installed using:

  • Paket
  • NuGet command line
  • NuGet Package Manager in Visual Studio.

Install using the command line:

paket add IDisposableAnalyzers --project <project>

or if you prefer NuGet

Install-Package IDisposableAnalyzers

Updating

The ruleset editor does not handle changed IDs well, if things get out of sync you can try:

  1. Close visual studio.
  2. Edit the ProjectName.rulset file and remove the IDisposableAnalyzers element.
  3. Start visual studio and add back the desired configuration.

Above is not ideal, sorry about this. Not sure if this is our bug.

Current status

Early alpha, finds bugs in the code but there are also bugs in the analyzer. The analyzer will probably never be perfect as it is a pretty hard problem to solve but we can improve it one test case at the time. Write issues for places where it should warn but does not or where it warns where there is no bug.

About

Roslyn analyzers for IDisposable

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.8%
  • PowerShell 0.2%