From 2ad3a9cae33ed5cdebb42a1233a1a704e86d5399 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Wed, 6 Dec 2017 12:56:04 -0800 Subject: [PATCH 1/4] Add workaround for #1318 to unblock unit tests --- ...ectionOnAnImmutableCollectionValueTests.cs | 433 +++++++++++++----- .../DiagnosticAnalyzerTestBase.cs | 7 +- 2 files changed, 324 insertions(+), 116 deletions(-) diff --git a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs index 52aa12b422..dbc0ca40c8 100644 --- a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs +++ b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs @@ -23,6 +23,299 @@ public class DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests : D nameof(ImmutableSortedDictionary) }; + #region CSharpCollectionsDefinition + + private const string CSharpCollectionsDefinition = @" +using System.Collections.Generic; +using System.Collections.Immutable; +using static System.Collections.Immutable.ImmutableExtensions; + +namespace System.Collections.Immutable +{ + public sealed partial class ImmutableArray : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public sealed partial class ImmutableList : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public sealed partial class ImmutableHashSet : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public sealed partial class ImmutableSortedSet : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public sealed partial class ImmutableDictionary : IEnumerable> + { + public IEnumerator> GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public sealed partial class ImmutableSortedDictionary : IEnumerable> + { + public IEnumerator> GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + + public static class ImmutableExtensions + { + public static ImmutableArray ToImmutableArray(this IEnumerable source) + { + return null; + } + + public static ImmutableArray ToImmutableArray(this IEnumerable source, IEqualityComparer comparer) + { + return null; + } + + public static ImmutableList ToImmutableList(this IEnumerable source) + { + return null; + } + + public static ImmutableList ToImmutableList(this IEnumerable source, IEqualityComparer comparer) + { + return null; + } + + public static ImmutableHashSet ToImmutableHashSet(this IEnumerable source) + { + return null; + } + + public static ImmutableHashSet ToImmutableHashSet(this IEnumerable source, IEqualityComparer comparer) + { + return null; + } + + public static ImmutableSortedSet ToImmutableSortedSet(this IEnumerable source) + { + return null; + } + + public static ImmutableSortedSet ToImmutableSortedSet(this IEnumerable source, IEqualityComparer comparer) + { + return null; + } + + public static ImmutableDictionary ToImmutableDictionary(this IEnumerable> source) + { + return null; + } + + public static ImmutableDictionary ToImmutableDictionary(this IEnumerable> source, IEqualityComparer keyComparer) + { + return null; + } + + public static ImmutableSortedDictionary ToImmutableSortedDictionary(this IEnumerable> source) + { + return null; + } + + public static ImmutableSortedDictionary ToImmutableSortedDictionary(this IEnumerable> source, IEqualityComparer keyComparer) + { + return null; + } + } +} +"; + private const string VisualBasicCollectionsDefinition = @" +Imports System +Imports System.Collections +Imports System.Collections.Generic +Imports System.Collections.Immutable +Imports System.Collections.Immutable.ImmutableExtensions +Imports System.Runtime.CompilerServices + +Namespace System.Collections.Immutable + + Partial Public NotInheritable Class ImmutableArray(Of T) + Implements IEnumerable(Of T) + + Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Partial Public NotInheritable Class ImmutableList(Of T) + Implements IEnumerable(Of T) + Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Partial Public NotInheritable Class ImmutableHashSet(Of T) + Implements IEnumerable(Of T) + Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Partial Public NotInheritable Class ImmutableSortedSet(Of T) + Implements IEnumerable(Of T) + Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Partial Public NotInheritable Class ImmutableDictionary(Of TKey, TValue) + Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)) + Public Function GetEnumerator() As IEnumerator(Of KeyValuePair(Of TKey, TValue)) Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Partial Public NotInheritable Class ImmutableSortedDictionary(Of TKey, TValue) + Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)) + Public Function GetEnumerator() As IEnumerator(Of KeyValuePair(Of TKey, TValue)) Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)).GetEnumerator + Throw New NotImplementedException() + End Function + + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Throw New NotImplementedException() + End Function + End Class + + Module ImmutableExtensions + + Function ToImmutableArray(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableArray(Of T) + Return Nothing + End Function + + + Function ToImmutableArray(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableArray(Of T) + Return Nothing + End Function + + + Function ToImmutableList(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableList(Of T) + Return Nothing + End Function + + + Function ToImmutableList(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableList(Of T) + Return Nothing + End Function + + + Function ToImmutableHashSet(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableHashSet(Of T) + Return Nothing + End Function + + + Function ToImmutableHashSet(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableHashSet(Of T) + Return Nothing + End Function + + + Function ToImmutableSortedSet(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableSortedSet(Of T) + Return Nothing + End Function + + + Function ToImmutableSortedSet(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableSortedSet(Of T) + Return Nothing + End Function + + + Function ToImmutableDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As ImmutableDictionary(Of TKey, TValue) + Return Nothing + End Function + + + Function ToImmutableDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue)), ByVal keyComparer As IEqualityComparer(Of TKey)) As ImmutableDictionary(Of TKey, TValue) + Return Nothing + End Function + + + Function ToImmutableSortedDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As ImmutableSortedDictionary(Of TKey, TValue) + Return Nothing + End Function + + + Function ToImmutableSortedDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue)), ByVal keyComparer As IEqualityComparer(Of TKey)) As ImmutableSortedDictionary(Of TKey, TValue) + Return Nothing + End Function + End Module +End Namespace +"; + #endregion + protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer() { return new DoNotCallToImmutableCollectionOnAnImmutableCollectionValueAnalyzer(); @@ -39,19 +332,7 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() [MemberData(nameof(CollectionNames_Arity1))] public void NoDiagnosticCases_Arity1(string collectionName) { - VerifyCSharp($@" -using System.Collections.Generic; -using System.Collections.Immutable; -using static System.Collections.Immutable.{collectionName}; - -static class Extensions -{{ - public static {collectionName} To{collectionName}(this IEnumerable items) - {{ - return default({collectionName}); - }} -}} - + VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ public void M(IEnumerable p1, List p2, {collectionName} p3) @@ -67,17 +348,7 @@ public void M(IEnumerable p1, List p2, {collectionName} p3) }} "); - VerifyBasic($@" -Imports System.Collections.Generic -Imports System.Collections.Immutable - -Module Extensions - _ - Public Function To{collectionName}(Of TSource)(items As IEnumerable(Of TSource)) As {collectionName}(Of TSource) - Return Nothing - End Function -End Module - + VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer)) ' Allowed @@ -96,19 +367,7 @@ End Class [MemberData(nameof(CollectionNames_Arity2))] public void NoDiagnosticCases_Arity2(string collectionName) { - VerifyCSharp($@" -using System.Collections.Generic; -using System.Collections.Immutable; -using static System.Collections.Immutable.{collectionName}; - -static class Extensions -{{ - public static {collectionName} To{collectionName}(this IEnumerable> items) - {{ - return default({collectionName}); - }} -}} - + VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ public void M(IEnumerable> p1, List> p2, {collectionName} p3) @@ -124,17 +383,7 @@ public void M(IEnumerable> p1, List _ - Public Function To{collectionName}(Of TKey, TValue)(items As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As {collectionName}(Of TKey, TValue) - Return Nothing - End Function -End Module - + VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List(Of KeyValuePair(Of Integer, Integer)), p3 As {collectionName}(Of Integer, Integer)) ' Allowed @@ -153,23 +402,11 @@ End Class #region Diagnostic Tests - [Theory(Skip = "https://github.com/dotnet/roslyn-analyzers/issues/1318")] + [Theory] [MemberData(nameof(CollectionNames_Arity1))] public void DiagnosticCases_Arity1(string collectionName) { - VerifyCSharp($@" -using System.Collections.Generic; -using System.Collections.Immutable; -using static System.Collections.Immutable.{collectionName}; - -static class Extensions -{{ - public static {collectionName} To{collectionName}(this IEnumerable items) - {{ - return default({collectionName}); - }} -}} - + VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ public void M(IEnumerable p1, List p2, {collectionName} p3) @@ -179,22 +416,12 @@ public void M(IEnumerable p1, List p2, {collectionName} p3) }} }} ", - // Test0.cs(18,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetCSharpResultAt(18, 9, collectionName), - // Test0.cs(19,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetCSharpResultAt(19, 9, collectionName)); - - VerifyBasic($@" -Imports System.Collections.Generic -Imports System.Collections.Immutable - -Module Extensions - _ - Public Function To{collectionName}(Of TSource)(items As IEnumerable(Of TSource)) As {collectionName}(Of TSource) - Return Nothing - End Function -End Module + // Test0.cs(154,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(154, 9, collectionName), + // Test0.cs(155,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(155, 9, collectionName)); + VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer)) p1.To{collectionName}().To{collectionName}() @@ -202,29 +429,17 @@ Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {colle End Sub End Class ", - // Test0.vb(14,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(14, 3, collectionName), - // Test0.vb(15,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(15, 3, collectionName)); + // Test0.vb(143,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(143, 3, collectionName), + // Test0.vb(144,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(144, 3, collectionName)); } - [Theory(Skip = "https://github.com/dotnet/roslyn-analyzers/issues/1318")] + [Theory] [MemberData(nameof(CollectionNames_Arity2))] public void DiagnosticCases_Arity2(string collectionName) { - VerifyCSharp($@" -using System.Collections.Generic; -using System.Collections.Immutable; -using static System.Collections.Immutable.{collectionName}; - -static class Extensions -{{ - public static {collectionName} To{collectionName}(this IEnumerable> items) - {{ - return default({collectionName}); - }} -}} - + VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ public void M(IEnumerable> p1, List> p2, {collectionName} p3) @@ -234,22 +449,12 @@ public void M(IEnumerable> p1, List _ - Public Function To{collectionName}(Of TKey, TValue)(items As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As {collectionName}(Of TKey, TValue) - Return Nothing - End Function -End Module + // Test0.cs(154,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(154, 9, collectionName), + // Test0.cs(155,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(155, 9, collectionName)); + VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List(Of KeyValuePair(Of Integer, Integer)), p3 As {collectionName}(Of Integer, Integer)) p1.To{collectionName}().To{collectionName}() @@ -257,10 +462,10 @@ Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List End Sub End Class ", - // Test0.vb(14,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(14, 3, collectionName), - // Test0.vb(15,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(15, 3, collectionName)); + // Test0.vb(143,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(143, 3, collectionName), + // Test0.vb(144,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(144, 3, collectionName)); } #endregion diff --git a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs index 302aab67ae..22917a48be 100644 --- a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs +++ b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs @@ -28,13 +28,16 @@ public abstract class DiagnosticAnalyzerTestBase private static readonly MetadataReference s_visualBasicReference = MetadataReference.CreateFromFile(typeof(Microsoft.VisualBasic.Devices.ComputerInfo).Assembly.Location); private static readonly MetadataReference s_codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); private static readonly MetadataReference s_workspacesReference = MetadataReference.CreateFromFile(typeof(Workspace).Assembly.Location); - private static readonly MetadataReference s_immutableCollectionsReference = MetadataReference.CreateFromFile(typeof(ImmutableArray).Assembly.Location); private static readonly MetadataReference s_systemDiagnosticsDebugReference = MetadataReference.CreateFromFile(typeof(Debug).Assembly.Location); private static readonly MetadataReference s_systemDataReference = MetadataReference.CreateFromFile(typeof(System.Data.DataSet).Assembly.Location); protected static readonly CompilationOptions s_CSharpDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); protected static readonly CompilationOptions s_CSharpUnsafeCodeDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithAllowUnsafe(true); protected static readonly CompilationOptions s_visualBasicDefaultOptions = new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary); +#pragma warning disable CA1823 // Avoid unused private fields https://github.com/dotnet/roslyn-analyzers/issues/1318 + private static readonly MetadataReference s_immutableCollectionsReference = MetadataReference.CreateFromFile(typeof(ImmutableArray).Assembly.Location); +#pragma warning restore CA1823 // Avoid unused private fields + internal const string DefaultFilePathPrefix = "Test"; internal const string CSharpDefaultFileExt = "cs"; internal const string VisualBasicDefaultExt = "vb"; @@ -372,7 +375,7 @@ private static Project CreateProject( .AddMetadataReference(projectId, SystemRuntimeFacadeRef) .AddMetadataReference(projectId, SystemThreadingFacadeRef) .AddMetadataReference(projectId, SystemThreadingTaskFacadeRef) - .AddMetadataReference(projectId, s_immutableCollectionsReference) + //.AddMetadataReference(projectId, s_immutableCollectionsReference) https://github.com/dotnet/roslyn-analyzers/issues/1318 .AddMetadataReference(projectId, s_workspacesReference) .AddMetadataReference(projectId, s_systemDiagnosticsDebugReference) .AddMetadataReference(projectId, s_systemDataReference) From 5bd1b458584f1e08dbdfeee6b9196ab20e7e78f2 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Wed, 6 Dec 2017 14:01:17 -0800 Subject: [PATCH 2/4] Do not flag RS0012 for ToImmutable invocations if the contents of the underlying collection could be modified by the invoked API. Fixes #1430 --- ...eCollectionOnAnImmutableCollectionValue.cs | 11 ++++++++++ ...ectionOnAnImmutableCollectionValueTests.cs | 20 +++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.NetCore.Analyzers/Core/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValue.cs b/src/Microsoft.NetCore.Analyzers/Core/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValue.cs index 6ee1dd7a97..cffd08a91a 100644 --- a/src/Microsoft.NetCore.Analyzers/Core/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValue.cs +++ b/src/Microsoft.NetCore.Analyzers/Core/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValue.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Linq; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; using Microsoft.CodeAnalysis; @@ -67,6 +68,16 @@ public override void Initialize(AnalysisContext context) } Debug.Assert(!string.IsNullOrEmpty(metadataName)); + + // Do not flag invocations that take any explicit argument (comparer, converter, etc.) + // as they can potentially modify the contents of the resulting collection. + // See https://github.com/dotnet/roslyn/issues/23625 for language specific implementation below. + var argumentsToSkip = targetMethod.IsExtensionMethod && invocation.Language != LanguageNames.VisualBasic ? 1 : 0; + if (invocation.Arguments.Skip(argumentsToSkip).Any(arg => arg.ArgumentKind == ArgumentKind.Explicit)) + { + return; + } + var immutableCollectionType = compilation.GetTypeByMetadataName(metadataName); if (immutableCollectionType == null) { diff --git a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs index dbc0ca40c8..f33635f605 100644 --- a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs +++ b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs @@ -174,6 +174,10 @@ public static ImmutableSortedDictionary ToImmutableSortedDictionar } } "; + #endregion + + #region VisualBasicCollectionsDefinition + private const string VisualBasicCollectionsDefinition = @" Imports System Imports System.Collections @@ -328,18 +332,19 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() #region No Diagnostic Tests - [Theory] + [Theory, WorkItem(1432, "https://github.com/dotnet/roslyn-analyzers/issues/1432")] [MemberData(nameof(CollectionNames_Arity1))] public void NoDiagnosticCases_Arity1(string collectionName) { VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ - public void M(IEnumerable p1, List p2, {collectionName} p3) + public void M(IEnumerable p1, List p2, {collectionName} p3, IEqualityComparer comparer) {{ // Allowed p1.To{collectionName}(); p2.To{collectionName}(); + p3.To{collectionName}(comparer); // Potentially modifies the collection // No dataflow IEnumerable l1 = p3; @@ -350,10 +355,11 @@ public void M(IEnumerable p1, List p2, {collectionName} p3) VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C - Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer)) + Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer), comparer As IEqualityComparer(Of Integer)) ' Allowed p1.To{collectionName}() p2.To{collectionName}() + p3.To{collectionName}(comparer) ' Potentially modifies the collection ' No dataflow Dim l1 As IEnumerable(Of Integer) = p3 @@ -363,18 +369,19 @@ End Class "); } - [Theory] + [Theory, WorkItem(1432, "https://github.com/dotnet/roslyn-analyzers/issues/1432")] [MemberData(nameof(CollectionNames_Arity2))] public void NoDiagnosticCases_Arity2(string collectionName) { VerifyCSharp(CSharpCollectionsDefinition + $@" class C {{ - public void M(IEnumerable> p1, List> p2, {collectionName} p3) + public void M(IEnumerable> p1, List> p2, {collectionName} p3, IEqualityComparer keyComparer) {{ // Allowed p1.To{collectionName}(); p2.To{collectionName}(); + p3.To{collectionName}(keyComparer); // Potentially modifies the collection // No dataflow IEnumerable> l1 = p3; @@ -385,10 +392,11 @@ public void M(IEnumerable> p1, List Date: Wed, 6 Dec 2017 14:57:38 -0800 Subject: [PATCH 3/4] Revert the change to comment out SystemCollectionsImmutable reference as large number of tests depend on it --- ...ectionOnAnImmutableCollectionValueTests.cs | 453 +++++------------- ...crosoft.NetCore.Analyzers.UnitTests.csproj | 3 + .../DiagnosticAnalyzerTestBase.cs | 7 +- 3 files changed, 137 insertions(+), 326 deletions(-) diff --git a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs index f33635f605..d931108965 100644 --- a/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs +++ b/src/Microsoft.NetCore.Analyzers/UnitTests/ImmutableCollections/DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests.cs @@ -23,303 +23,6 @@ public class DoNotCallToImmutableCollectionOnAnImmutableCollectionValueTests : D nameof(ImmutableSortedDictionary) }; - #region CSharpCollectionsDefinition - - private const string CSharpCollectionsDefinition = @" -using System.Collections.Generic; -using System.Collections.Immutable; -using static System.Collections.Immutable.ImmutableExtensions; - -namespace System.Collections.Immutable -{ - public sealed partial class ImmutableArray : IEnumerable - { - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public sealed partial class ImmutableList : IEnumerable - { - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public sealed partial class ImmutableHashSet : IEnumerable - { - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public sealed partial class ImmutableSortedSet : IEnumerable - { - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public sealed partial class ImmutableDictionary : IEnumerable> - { - public IEnumerator> GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public sealed partial class ImmutableSortedDictionary : IEnumerable> - { - public IEnumerator> GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - - public static class ImmutableExtensions - { - public static ImmutableArray ToImmutableArray(this IEnumerable source) - { - return null; - } - - public static ImmutableArray ToImmutableArray(this IEnumerable source, IEqualityComparer comparer) - { - return null; - } - - public static ImmutableList ToImmutableList(this IEnumerable source) - { - return null; - } - - public static ImmutableList ToImmutableList(this IEnumerable source, IEqualityComparer comparer) - { - return null; - } - - public static ImmutableHashSet ToImmutableHashSet(this IEnumerable source) - { - return null; - } - - public static ImmutableHashSet ToImmutableHashSet(this IEnumerable source, IEqualityComparer comparer) - { - return null; - } - - public static ImmutableSortedSet ToImmutableSortedSet(this IEnumerable source) - { - return null; - } - - public static ImmutableSortedSet ToImmutableSortedSet(this IEnumerable source, IEqualityComparer comparer) - { - return null; - } - - public static ImmutableDictionary ToImmutableDictionary(this IEnumerable> source) - { - return null; - } - - public static ImmutableDictionary ToImmutableDictionary(this IEnumerable> source, IEqualityComparer keyComparer) - { - return null; - } - - public static ImmutableSortedDictionary ToImmutableSortedDictionary(this IEnumerable> source) - { - return null; - } - - public static ImmutableSortedDictionary ToImmutableSortedDictionary(this IEnumerable> source, IEqualityComparer keyComparer) - { - return null; - } - } -} -"; - #endregion - - #region VisualBasicCollectionsDefinition - - private const string VisualBasicCollectionsDefinition = @" -Imports System -Imports System.Collections -Imports System.Collections.Generic -Imports System.Collections.Immutable -Imports System.Collections.Immutable.ImmutableExtensions -Imports System.Runtime.CompilerServices - -Namespace System.Collections.Immutable - - Partial Public NotInheritable Class ImmutableArray(Of T) - Implements IEnumerable(Of T) - - Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Partial Public NotInheritable Class ImmutableList(Of T) - Implements IEnumerable(Of T) - Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Partial Public NotInheritable Class ImmutableHashSet(Of T) - Implements IEnumerable(Of T) - Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Partial Public NotInheritable Class ImmutableSortedSet(Of T) - Implements IEnumerable(Of T) - Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Partial Public NotInheritable Class ImmutableDictionary(Of TKey, TValue) - Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)) - Public Function GetEnumerator() As IEnumerator(Of KeyValuePair(Of TKey, TValue)) Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Partial Public NotInheritable Class ImmutableSortedDictionary(Of TKey, TValue) - Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)) - Public Function GetEnumerator() As IEnumerator(Of KeyValuePair(Of TKey, TValue)) Implements IEnumerable(Of KeyValuePair(Of TKey, TValue)).GetEnumerator - Throw New NotImplementedException() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Throw New NotImplementedException() - End Function - End Class - - Module ImmutableExtensions - - Function ToImmutableArray(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableArray(Of T) - Return Nothing - End Function - - - Function ToImmutableArray(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableArray(Of T) - Return Nothing - End Function - - - Function ToImmutableList(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableList(Of T) - Return Nothing - End Function - - - Function ToImmutableList(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableList(Of T) - Return Nothing - End Function - - - Function ToImmutableHashSet(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableHashSet(Of T) - Return Nothing - End Function - - - Function ToImmutableHashSet(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableHashSet(Of T) - Return Nothing - End Function - - - Function ToImmutableSortedSet(Of T)(ByVal source As IEnumerable(Of T)) As ImmutableSortedSet(Of T) - Return Nothing - End Function - - - Function ToImmutableSortedSet(Of T)(ByVal source As IEnumerable(Of T), ByVal comparer As IEqualityComparer(Of T)) As ImmutableSortedSet(Of T) - Return Nothing - End Function - - - Function ToImmutableDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As ImmutableDictionary(Of TKey, TValue) - Return Nothing - End Function - - - Function ToImmutableDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue)), ByVal keyComparer As IEqualityComparer(Of TKey)) As ImmutableDictionary(Of TKey, TValue) - Return Nothing - End Function - - - Function ToImmutableSortedDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As ImmutableSortedDictionary(Of TKey, TValue) - Return Nothing - End Function - - - Function ToImmutableSortedDictionary(Of TKey, TValue)(ByVal source As IEnumerable(Of KeyValuePair(Of TKey, TValue)), ByVal keyComparer As IEqualityComparer(Of TKey)) As ImmutableSortedDictionary(Of TKey, TValue) - Return Nothing - End Function - End Module -End Namespace -"; - #endregion - protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer() { return new DoNotCallToImmutableCollectionOnAnImmutableCollectionValueAnalyzer(); @@ -336,7 +39,24 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() [MemberData(nameof(CollectionNames_Arity1))] public void NoDiagnosticCases_Arity1(string collectionName) { - VerifyCSharp(CSharpCollectionsDefinition + $@" + VerifyCSharp($@" +using System.Collections.Generic; +using System.Collections.Immutable; +using static System.Collections.Immutable.{collectionName}; + +static class Extensions +{{ + public static {collectionName} To{collectionName}(this IEnumerable items) + {{ + return default({collectionName}); + }} + + public static {collectionName} To{collectionName}(this IEnumerable items, IEqualityComparer comparer) + {{ + return default({collectionName}); + }} +}} + class C {{ public void M(IEnumerable p1, List p2, {collectionName} p3, IEqualityComparer comparer) @@ -353,7 +73,22 @@ public void M(IEnumerable p1, List p2, {collectionName} p3, IEqua }} "); - VerifyBasic(VisualBasicCollectionsDefinition + $@" + VerifyBasic($@" +Imports System.Collections.Generic +Imports System.Collections.Immutable + +Module Extensions + _ + Public Function To{collectionName}(Of TSource)(items As IEnumerable(Of TSource)) As {collectionName}(Of TSource) + Return Nothing + End Function + + _ + Public Function To{collectionName}(Of TSource)(items As IEnumerable(Of TSource), comparer as IEqualityComparer(Of TSource)) As {collectionName}(Of TSource) + Return Nothing + End Function +End Module + Class C Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer), comparer As IEqualityComparer(Of Integer)) ' Allowed @@ -373,7 +108,24 @@ End Class [MemberData(nameof(CollectionNames_Arity2))] public void NoDiagnosticCases_Arity2(string collectionName) { - VerifyCSharp(CSharpCollectionsDefinition + $@" + VerifyCSharp($@" +using System.Collections.Generic; +using System.Collections.Immutable; +using static System.Collections.Immutable.{collectionName}; + +static class Extensions +{{ + public static {collectionName} To{collectionName}(this IEnumerable> items) + {{ + return default({collectionName}); + }} + + public static {collectionName} To{collectionName}(this IEnumerable> items, IEqualityComparer keyComparer) + {{ + return default({collectionName}); + }} +}} + class C {{ public void M(IEnumerable> p1, List> p2, {collectionName} p3, IEqualityComparer keyComparer) @@ -390,7 +142,22 @@ public void M(IEnumerable> p1, List _ + Public Function To{collectionName}(Of TKey, TValue)(items As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As {collectionName}(Of TKey, TValue) + Return Nothing + End Function + + _ + Public Function To{collectionName}(Of TKey, TValue)(items As IEnumerable(Of KeyValuePair(Of TKey, TValue)), keyComparer As IEqualityComparer(Of TKey)) As {collectionName}(Of TKey, TValue) + Return Nothing + End Function +End Module + Class C Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List(Of KeyValuePair(Of Integer, Integer)), p3 As {collectionName}(Of Integer, Integer), keyComparer As IEqualityComparer(Of Integer)) ' Allowed @@ -414,7 +181,19 @@ End Class [MemberData(nameof(CollectionNames_Arity1))] public void DiagnosticCases_Arity1(string collectionName) { - VerifyCSharp(CSharpCollectionsDefinition + $@" + VerifyCSharp($@" +using System.Collections.Generic; +using System.Collections.Immutable; +using static System.Collections.Immutable.{collectionName}; + +static class Extensions +{{ + public static {collectionName} To{collectionName}(this IEnumerable items) + {{ + return default({collectionName}); + }} +}} + class C {{ public void M(IEnumerable p1, List p2, {collectionName} p3) @@ -424,12 +203,22 @@ public void M(IEnumerable p1, List p2, {collectionName} p3) }} }} ", - // Test0.cs(154,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetCSharpResultAt(154, 9, collectionName), - // Test0.cs(155,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetCSharpResultAt(155, 9, collectionName)); + // Test0.cs(18,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(18, 9, collectionName), + // Test0.cs(19,9): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetCSharpResultAt(19, 9, collectionName)); + + VerifyBasic($@" +Imports System.Collections.Generic +Imports System.Collections.Immutable + +Module Extensions + _ + Public Function To{collectionName}(Of TSource)(items As IEnumerable(Of TSource)) As {collectionName}(Of TSource) + Return Nothing + End Function +End Module - VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {collectionName}(Of Integer)) p1.To{collectionName}().To{collectionName}() @@ -437,17 +226,29 @@ Public Sub M(p1 As IEnumerable(Of Integer), p2 As List(Of Integer), p3 As {colle End Sub End Class ", - // Test0.vb(143,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(143, 3, collectionName), - // Test0.vb(144,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(144, 3, collectionName)); + // Test0.vb(14,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(14, 3, collectionName), + // Test0.vb(15,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(15, 3, collectionName)); } [Theory] [MemberData(nameof(CollectionNames_Arity2))] public void DiagnosticCases_Arity2(string collectionName) { - VerifyCSharp(CSharpCollectionsDefinition + $@" + VerifyCSharp($@" +using System.Collections.Generic; +using System.Collections.Immutable; +using static System.Collections.Immutable.{collectionName}; + +static class Extensions +{{ + public static {collectionName} To{collectionName}(this IEnumerable> items) + {{ + return default({collectionName}); + }} +}} + class C {{ public void M(IEnumerable> p1, List> p2, {collectionName} p3) @@ -457,12 +258,22 @@ public void M(IEnumerable> p1, List _ + Public Function To{collectionName}(Of TKey, TValue)(items As IEnumerable(Of KeyValuePair(Of TKey, TValue))) As {collectionName}(Of TKey, TValue) + Return Nothing + End Function +End Module - VerifyBasic(VisualBasicCollectionsDefinition + $@" Class C Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List(Of KeyValuePair(Of Integer, Integer)), p3 As {collectionName}(Of Integer, Integer)) p1.To{collectionName}().To{collectionName}() @@ -470,10 +281,10 @@ Public Sub M(p1 As IEnumerable(Of KeyValuePair(Of Integer, Integer)), p2 As List End Sub End Class ", - // Test0.vb(143,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(143, 3, collectionName), - // Test0.vb(144,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value - GetBasicResultAt(144, 3, collectionName)); + // Test0.vb(14,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(14, 3, collectionName), + // Test0.vb(15,3): warning RS0012: Do not call ToImmutableCollection on an ImmutableCollection value + GetBasicResultAt(15, 3, collectionName)); } #endregion diff --git a/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj b/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj index c2bfc9ee24..b04cfeb279 100644 --- a/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj +++ b/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj @@ -9,4 +9,7 @@ + + + \ No newline at end of file diff --git a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs index 22917a48be..e8d01f62eb 100644 --- a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs +++ b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs @@ -29,15 +29,12 @@ public abstract class DiagnosticAnalyzerTestBase private static readonly MetadataReference s_codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); private static readonly MetadataReference s_workspacesReference = MetadataReference.CreateFromFile(typeof(Workspace).Assembly.Location); private static readonly MetadataReference s_systemDiagnosticsDebugReference = MetadataReference.CreateFromFile(typeof(Debug).Assembly.Location); + private static readonly MetadataReference s_immutableCollectionsReference = MetadataReference.CreateFromFile(typeof(ImmutableArray).Assembly.Location); private static readonly MetadataReference s_systemDataReference = MetadataReference.CreateFromFile(typeof(System.Data.DataSet).Assembly.Location); protected static readonly CompilationOptions s_CSharpDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); protected static readonly CompilationOptions s_CSharpUnsafeCodeDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithAllowUnsafe(true); protected static readonly CompilationOptions s_visualBasicDefaultOptions = new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary); -#pragma warning disable CA1823 // Avoid unused private fields https://github.com/dotnet/roslyn-analyzers/issues/1318 - private static readonly MetadataReference s_immutableCollectionsReference = MetadataReference.CreateFromFile(typeof(ImmutableArray).Assembly.Location); -#pragma warning restore CA1823 // Avoid unused private fields - internal const string DefaultFilePathPrefix = "Test"; internal const string CSharpDefaultFileExt = "cs"; internal const string VisualBasicDefaultExt = "vb"; @@ -375,7 +372,7 @@ private static Project CreateProject( .AddMetadataReference(projectId, SystemRuntimeFacadeRef) .AddMetadataReference(projectId, SystemThreadingFacadeRef) .AddMetadataReference(projectId, SystemThreadingTaskFacadeRef) - //.AddMetadataReference(projectId, s_immutableCollectionsReference) https://github.com/dotnet/roslyn-analyzers/issues/1318 + .AddMetadataReference(projectId, s_immutableCollectionsReference) .AddMetadataReference(projectId, s_workspacesReference) .AddMetadataReference(projectId, s_systemDiagnosticsDebugReference) .AddMetadataReference(projectId, s_systemDataReference) From b71a93e2de79bd4b7ed5d3573d99efbedcdde870 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Wed, 6 Dec 2017 14:59:26 -0800 Subject: [PATCH 4/4] Remove couple of accidental unncessary changes --- .../UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj | 3 --- src/Test.Utilities/DiagnosticAnalyzerTestBase.cs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj b/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj index b04cfeb279..c2bfc9ee24 100644 --- a/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj +++ b/src/Microsoft.NetCore.Analyzers/UnitTests/Microsoft.NetCore.Analyzers.UnitTests.csproj @@ -9,7 +9,4 @@ - - - \ No newline at end of file diff --git a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs index e8d01f62eb..302aab67ae 100644 --- a/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs +++ b/src/Test.Utilities/DiagnosticAnalyzerTestBase.cs @@ -28,8 +28,8 @@ public abstract class DiagnosticAnalyzerTestBase private static readonly MetadataReference s_visualBasicReference = MetadataReference.CreateFromFile(typeof(Microsoft.VisualBasic.Devices.ComputerInfo).Assembly.Location); private static readonly MetadataReference s_codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); private static readonly MetadataReference s_workspacesReference = MetadataReference.CreateFromFile(typeof(Workspace).Assembly.Location); - private static readonly MetadataReference s_systemDiagnosticsDebugReference = MetadataReference.CreateFromFile(typeof(Debug).Assembly.Location); private static readonly MetadataReference s_immutableCollectionsReference = MetadataReference.CreateFromFile(typeof(ImmutableArray).Assembly.Location); + private static readonly MetadataReference s_systemDiagnosticsDebugReference = MetadataReference.CreateFromFile(typeof(Debug).Assembly.Location); private static readonly MetadataReference s_systemDataReference = MetadataReference.CreateFromFile(typeof(System.Data.DataSet).Assembly.Location); protected static readonly CompilationOptions s_CSharpDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); protected static readonly CompilationOptions s_CSharpUnsafeCodeDefaultOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithAllowUnsafe(true);