diff --git a/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj b/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj index 31cc076b..7ee7cacf 100644 --- a/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj +++ b/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj @@ -14,6 +14,7 @@ + diff --git a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs index 7214721d..f5a26b27 100644 --- a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs +++ b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs @@ -21,4 +21,5 @@ typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt), typeof(Gu.Roslyn.CodeFixExtensions.Parse), typeof(Stubs.Extensions), + typeof(IDisposableAnnotations.GivesOwnershipAttribute), typeof(NUnit.Framework.Assert))] diff --git a/IDisposableAnalyzers.sln b/IDisposableAnalyzers.sln index c258f648..729b1f90 100644 --- a/IDisposableAnalyzers.sln +++ b/IDisposableAnalyzers.sln @@ -58,6 +58,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stubs", "Stubs\Stubs.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidCode", "ValidCode\ValidCode.csproj", "{C6A235B1-A780-43D5-BA1F-E31861C019F5}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDisposableAnnotations", "IDisposableAnnotations\IDisposableAnnotations.csproj", "{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -92,6 +94,10 @@ Global {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.Build.0 = Release|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IDisposableAnalyzers/IDisposableAnalyzers.csproj b/IDisposableAnalyzers/IDisposableAnalyzers.csproj index 9e92e983..8175f69b 100644 --- a/IDisposableAnalyzers/IDisposableAnalyzers.csproj +++ b/IDisposableAnalyzers/IDisposableAnalyzers.csproj @@ -20,13 +20,11 @@ - 2.0.5.0 + 2.0.6.0 Johan Larsson, milleniumbug false - IDISP004 warn on explicit discard. -IDISP017 when disposing in finally. -IDISP003 when assigning in loop. - + BUGFIX: IDISP003 figure out when assigned in switch. +IDISP003 should not warn when assigning out parameter in if return. IDisposable Roslyn Diagnostic Analyzer DotnetAnalyzers BUGFIX: Handle extension methods in binary references better. diff --git a/IDisposableAnalyzers/paket.template b/IDisposableAnalyzers/paket.template index e471fe66..b4d0e36f 100644 --- a/IDisposableAnalyzers/paket.template +++ b/IDisposableAnalyzers/paket.template @@ -1,13 +1,11 @@ type project -include-referenced-projects true developmentDependency true projectUrl https://github.com/DotNetAnalyzers/IDisposableAnalyzers licenseUrl http://opensource.org/licenses/MIT releaseNotes - IDISP004 warn on explicit discard. - IDISP017 when disposing in finally. - IDISP003 when assigning in loop. + BUGFIX: IDISP003 figure out when assigned in switch. + IDISP003 should not warn when assigning out parameter in if return. excludedgroups Main diff --git a/IDisposableAnnotations/GivesOwnershipAttribute.cs b/IDisposableAnnotations/GivesOwnershipAttribute.cs new file mode 100644 index 00000000..77c8fee1 --- /dev/null +++ b/IDisposableAnnotations/GivesOwnershipAttribute.cs @@ -0,0 +1,12 @@ +namespace IDisposableAnnotations +{ + using System; + + /// + /// The return value must be disposed by the caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class GivesOwnershipAttribute : Attribute + { + } +} diff --git a/IDisposableAnnotations/IDisposableAnnotations.csproj b/IDisposableAnnotations/IDisposableAnnotations.csproj new file mode 100644 index 00000000..df463b7a --- /dev/null +++ b/IDisposableAnnotations/IDisposableAnnotations.csproj @@ -0,0 +1,5 @@ + + + netstandard1.0 + + diff --git a/IDisposableAnnotations/KeepsOwnershipAttribute.cs b/IDisposableAnnotations/KeepsOwnershipAttribute.cs new file mode 100644 index 00000000..452ec0b5 --- /dev/null +++ b/IDisposableAnnotations/KeepsOwnershipAttribute.cs @@ -0,0 +1,12 @@ +namespace IDisposableAnnotations +{ + using System; + + /// + /// The return value must not be disposed by the caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class KeepsOwnershipAttribute : Attribute + { + } +} diff --git a/IDisposableAnnotations/TakesOwnershipAttribute.cs b/IDisposableAnnotations/TakesOwnershipAttribute.cs new file mode 100644 index 00000000..6d1f8198 --- /dev/null +++ b/IDisposableAnnotations/TakesOwnershipAttribute.cs @@ -0,0 +1,12 @@ +namespace IDisposableAnnotations +{ + using System; + + /// + /// The ownership of instance is transferred and the receiver is responsible for disposing. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class TakesOwnershipAttribute : Attribute + { + } +} diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9172a35f..99ca27f5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +#### 2.0.6 +* BUGFIX: IDISP003 figure out when assigned in switch. +* IDISP003 should not warn when assigning out parameter in if return. + #### 2.0.5 * IDISP004 warn on explicit discard. * IDISP017 when disposing in finally. diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs new file mode 100644 index 00000000..92f7faad --- /dev/null +++ b/ValidCode/IWithAnnotations.cs @@ -0,0 +1,20 @@ +namespace ValidCode +{ + using System; + using IDisposableAnnotations; + + public interface IWithAnnotations + { + [return: GivesOwnership] + IDisposable Create(); + + bool TryCreate([GivesOwnership]out IDisposable disposable); + + [return: KeepsOwnership] + IDisposable GetOrCreate(); + + bool TryGet([KeepsOwnership]out IDisposable disposable); + + void Add([TakesOwnership] IDisposable disposable); + } +} diff --git a/ValidCode/ValidCode.csproj b/ValidCode/ValidCode.csproj index 0c38ebea..52f9bf76 100644 --- a/ValidCode/ValidCode.csproj +++ b/ValidCode/ValidCode.csproj @@ -7,4 +7,8 @@ + + + + \ No newline at end of file