From b305e14d7a2be1f942fb1c95c9d5fecbdb5727d8 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Wed, 12 Jan 2022 17:28:48 +1000 Subject: [PATCH] SA1127 Generic type constraints should be on their own line --- eng/Common.globalconfig | 2 +- .../LinkedObjectsMap.cs | 3 ++- .../BackEnd/LoggingServicesLogMethod_Tests.cs | 3 ++- .../BackEnd/BuildManager/BuildManager.cs | 3 ++- .../RequestBuilder/TargetUpToDateChecker.cs | 4 +++- .../Collections/ConcurrentQueueExtensions.cs | 3 ++- .../Collections/ConcurrentStackExtensions.cs | 6 +++-- .../HashSetDebugView.cs | 3 ++- src/Build/Evaluation/IItemProvider.cs | 3 ++- src/Build/Evaluation/IPropertyProvider.cs | 3 ++- src/Build/Evaluation/ItemSpec.cs | 4 +++- src/Build/Instance/ProjectInstance.cs | 3 ++- src/Build/Utilities/Utilities.cs | 3 ++- src/Shared/BinaryTranslator.cs | 12 ++++++---- src/Shared/ITranslator.cs | 6 +++-- src/Shared/NGen.cs | 3 ++- src/Shared/TranslatorHelpers.cs | 22 +++++++++++++------ src/Shared/UnitTests/TestEnvironment.cs | 6 +++-- src/Tasks/RCWForCurrentContext.cs | 3 ++- 19 files changed, 64 insertions(+), 31 deletions(-) diff --git a/eng/Common.globalconfig b/eng/Common.globalconfig index ba417e063f2..578d621da2e 100644 --- a/eng/Common.globalconfig +++ b/eng/Common.globalconfig @@ -823,7 +823,7 @@ dotnet_diagnostic.SA1124.severity = none dotnet_diagnostic.SA1125.severity = warning # Generic type constraints should be on their own line -dotnet_diagnostic.SA1127.severity = suggestion +dotnet_diagnostic.SA1127.severity = warning # Put constructor initializers on their own line dotnet_diagnostic.SA1128.severity = suggestion diff --git a/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/LinkedObjectsMap.cs b/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/LinkedObjectsMap.cs index da3a45fc598..db5874402c5 100644 --- a/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/LinkedObjectsMap.cs +++ b/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/LinkedObjectsMap.cs @@ -173,7 +173,8 @@ public bool GetOrCreate(SourceType source, object context, return GetOrCreate(source.Key, source, context, out linked, slow); } - public bool GetOrCreate(KeyType key, SourceType source, object context, out LinkType linked, bool slow = false) where LinkType : LinkedObject, new() + public bool GetOrCreate(KeyType key, SourceType source, object context, out LinkType linked, bool slow = false) + where LinkType : LinkedObject, new() { if (source == null) { diff --git a/src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs b/src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs index 3e69b611fdf..d8c7a32b27d 100644 --- a/src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs +++ b/src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs @@ -1925,7 +1925,8 @@ internal void ResetProcessedBuildEvent() #endregion } - private class EventArgsEqualityComparer : IEqualityComparer where T : BuildEventArgs + private class EventArgsEqualityComparer : IEqualityComparer + where T : BuildEventArgs { public bool Equals(T x, T y) { diff --git a/src/Build/BackEnd/BuildManager/BuildManager.cs b/src/Build/BackEnd/BuildManager/BuildManager.cs index e2b4a71dc6f..3fc3f37b53f 100644 --- a/src/Build/BackEnd/BuildManager/BuildManager.cs +++ b/src/Build/BackEnd/BuildManager/BuildManager.cs @@ -3022,7 +3022,8 @@ private static void LogDeferredMessages(ILoggingService loggingService, IEnumera /// Ensures that the packet type matches the expected type /// /// The instance-type of packet being expected - private static I ExpectPacketType(INodePacket packet, NodePacketType expectedType) where I : class, INodePacket + private static I ExpectPacketType(INodePacket packet, NodePacketType expectedType) + where I : class, INodePacket { I castPacket = packet as I; diff --git a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs index 06b221c0d2f..0539caf47ce 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs @@ -907,7 +907,9 @@ private static List GetItemSpecsFromItemVectors(ItemVectorPartitionColle /// /// /// - private static void DiffHashtables(IDictionary h1, IDictionary h2, out List commonKeys, out List uniqueKeysInH1, out List uniqueKeysInH2) where K : class, IEquatable where V : class + private static void DiffHashtables(IDictionary h1, IDictionary h2, out List commonKeys, out List uniqueKeysInH1, out List uniqueKeysInH2) + where K : class, IEquatable + where V : class { commonKeys = new List(); uniqueKeysInH1 = new List(); diff --git a/src/Build/Collections/ConcurrentQueueExtensions.cs b/src/Build/Collections/ConcurrentQueueExtensions.cs index 6160e4605a9..97176d04afa 100644 --- a/src/Build/Collections/ConcurrentQueueExtensions.cs +++ b/src/Build/Collections/ConcurrentQueueExtensions.cs @@ -17,7 +17,8 @@ internal static class ConcurrentQueueExtensions /// The dequeue method. /// /// The type contained within the queue - public static T Dequeue(this ConcurrentQueue stack) where T : class + public static T Dequeue(this ConcurrentQueue stack) + where T : class { ErrorUtilities.VerifyThrow(stack.TryDequeue(out T result), "Unable to dequeue from queue"); return result; diff --git a/src/Build/Collections/ConcurrentStackExtensions.cs b/src/Build/Collections/ConcurrentStackExtensions.cs index e4a552676d9..1b0745e2885 100644 --- a/src/Build/Collections/ConcurrentStackExtensions.cs +++ b/src/Build/Collections/ConcurrentStackExtensions.cs @@ -17,7 +17,8 @@ internal static class ConcurrentStackExtensions /// The peek method. /// /// The type contained within the stack. - public static T Peek(this ConcurrentStack stack) where T : class + public static T Peek(this ConcurrentStack stack) + where T : class { ErrorUtilities.VerifyThrow(stack.TryPeek(out T result), "Unable to peek from stack"); return result; @@ -27,7 +28,8 @@ public static T Peek(this ConcurrentStack stack) where T : class /// The pop method. /// /// The type contained within the stack. - public static T Pop(this ConcurrentStack stack) where T : class + public static T Pop(this ConcurrentStack stack) + where T : class { ErrorUtilities.VerifyThrow(stack.TryPop(out T result), "Unable to pop from stack"); return result; diff --git a/src/Build/Collections/RetrievableEntryHashSet/HashSetDebugView.cs b/src/Build/Collections/RetrievableEntryHashSet/HashSetDebugView.cs index b4cd58a485b..cb231e08dec 100644 --- a/src/Build/Collections/RetrievableEntryHashSet/HashSetDebugView.cs +++ b/src/Build/Collections/RetrievableEntryHashSet/HashSetDebugView.cs @@ -12,7 +12,8 @@ namespace Microsoft.Build.Collections /// Debug view for HashSet /// /// - internal class HashSetDebugView where T : class, IKeyed + internal class HashSetDebugView + where T : class, IKeyed { private readonly RetrievableEntryHashSet _set; diff --git a/src/Build/Evaluation/IItemProvider.cs b/src/Build/Evaluation/IItemProvider.cs index cba344f2553..96050de96da 100644 --- a/src/Build/Evaluation/IItemProvider.cs +++ b/src/Build/Evaluation/IItemProvider.cs @@ -11,7 +11,8 @@ namespace Microsoft.Build.Evaluation /// This interface represents an object which can act as a source of items for the Expander. /// /// The type of items provided by the implementation. - internal interface IItemProvider where T : IItem + internal interface IItemProvider + where T : IItem { /// /// Returns a list of items with the specified item type. diff --git a/src/Build/Evaluation/IPropertyProvider.cs b/src/Build/Evaluation/IPropertyProvider.cs index 715cf119a36..f0ad85d5ce0 100644 --- a/src/Build/Evaluation/IPropertyProvider.cs +++ b/src/Build/Evaluation/IPropertyProvider.cs @@ -9,7 +9,8 @@ namespace Microsoft.Build.Evaluation /// An interface representing an object which can provide properties to the Expander. /// /// The type of properties provided. - internal interface IPropertyProvider where T : class + internal interface IPropertyProvider + where T : class { /// /// Returns a property with the specified name, or null if it was not found. diff --git a/src/Build/Evaluation/ItemSpec.cs b/src/Build/Evaluation/ItemSpec.cs index 8f1fb449206..62ef71b1b1a 100644 --- a/src/Build/Evaluation/ItemSpec.cs +++ b/src/Build/Evaluation/ItemSpec.cs @@ -568,7 +568,9 @@ public override IEnumerable GetReferencedItems() /// /// Property type /// Item type - internal sealed class MetadataTrie where P : class, IProperty where I : class, IItem, IMetadataTable + internal sealed class MetadataTrie + where P : class, IProperty + where I : class, IItem, IMetadataTable { private readonly Dictionary> _children; private readonly Func _normalize; diff --git a/src/Build/Instance/ProjectInstance.cs b/src/Build/Instance/ProjectInstance.cs index 3777ecbec35..8648d20f938 100644 --- a/src/Build/Instance/ProjectInstance.cs +++ b/src/Build/Instance/ProjectInstance.cs @@ -2640,7 +2640,8 @@ private static ObjectModel.ReadOnlyDictionary CreateCloneDiction /// /// The value stored in the dictionary /// Dictionary to clone. - private static IDictionary CreateCloneDictionary(IDictionary dictionary) where TValue : class, IKeyed + private static IDictionary CreateCloneDictionary(IDictionary dictionary) + where TValue : class, IKeyed { if (dictionary == null) { diff --git a/src/Build/Utilities/Utilities.cs b/src/Build/Utilities/Utilities.cs index 188c93e2bc9..e3cd4578688 100644 --- a/src/Build/Utilities/Utilities.cs +++ b/src/Build/Utilities/Utilities.cs @@ -597,7 +597,8 @@ public static int FastCountOrZero(this IEnumerable enumerable) /// /// Extension to IEnumerable of KVP of string, something to just return the somethings. /// - public static IEnumerable Values(this IEnumerable> source) where T : class, IKeyed + public static IEnumerable Values(this IEnumerable> source) + where T : class, IKeyed { foreach (var entry in source) { diff --git a/src/Shared/BinaryTranslator.cs b/src/Shared/BinaryTranslator.cs index b1540445884..1b562b46f4f 100644 --- a/src/Shared/BinaryTranslator.cs +++ b/src/Shared/BinaryTranslator.cs @@ -286,7 +286,8 @@ public void Translate(ref List list, ObjectTranslator objectTranslator) list = (List) listAsInterface; } - public void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : IList + public void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : IList { if (!TranslateNullable(list)) { @@ -313,7 +314,8 @@ public void Translate(ref IList list, ObjectTranslator objectTransla /// The factory to create the ICollection. /// The type contained in the collection. /// The type of collection to be created. - public void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : ICollection + public void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : ICollection { if (!TranslateNullable(collection)) { @@ -931,7 +933,8 @@ public void Translate(ref List list, ObjectTranslator objectTranslator) /// factory to create the IList /// A TaskItemType /// IList subtype - public void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : IList + public void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : IList { if (!TranslateNullable(list)) { @@ -956,7 +959,8 @@ public void Translate(ref IList list, ObjectTranslator objectTransla /// The factory to create the ICollection. /// The type contained in the collection. /// The type of collection to be created. - public void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : ICollection + public void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : ICollection { if (!TranslateNullable(collection)) { diff --git a/src/Shared/ITranslator.cs b/src/Shared/ITranslator.cs index 61dc02cc3a0..478fa1fbe43 100644 --- a/src/Shared/ITranslator.cs +++ b/src/Shared/ITranslator.cs @@ -180,7 +180,8 @@ BinaryWriter Writer /// An ITranslatable subtype /// An IList subtype /// factory to create a collection - void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : IList; + void Translate(ref IList list, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : IList; /// /// Translates a collection of T into the specified type using an and @@ -190,7 +191,8 @@ BinaryWriter Writer /// The factory to create the ICollection. /// The type contained in the collection. /// The type of collection to be created. - void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) where L : ICollection; + void Translate(ref ICollection collection, ObjectTranslator objectTranslator, NodePacketCollectionCreator collectionFactory) + where L : ICollection; /// /// Translates a DateTime. diff --git a/src/Shared/NGen.cs b/src/Shared/NGen.cs index 31276fe5fdd..6353fc75b93 100644 --- a/src/Shared/NGen.cs +++ b/src/Shared/NGen.cs @@ -16,7 +16,8 @@ namespace Microsoft.Build.Shared /// It works because although this is a value type, it is not defined in mscorlib. /// /// Wrapped type - internal struct NGen where T : struct + internal struct NGen + where T : struct { /// /// Wrapped value diff --git a/src/Shared/TranslatorHelpers.cs b/src/Shared/TranslatorHelpers.cs index 6850b11f1a2..299f808d297 100644 --- a/src/Shared/TranslatorHelpers.cs +++ b/src/Shared/TranslatorHelpers.cs @@ -29,7 +29,8 @@ internal static class TranslatorHelpers public static void Translate( this ITranslator translator, ref T instance, - NodePacketValueFactory valueFactory) where T : ITranslatable + NodePacketValueFactory valueFactory) + where T : ITranslatable { if (!translator.TranslateNullable(instance)) { @@ -45,7 +46,8 @@ public static void Translate( } } - static ObjectTranslator AdaptFactory(NodePacketValueFactory valueFactory) where T : ITranslatable + static ObjectTranslator AdaptFactory(NodePacketValueFactory valueFactory) + where T : ITranslatable { void TranslateUsingValueFactory(ITranslator translator, ref T objectToTranslate) { @@ -58,7 +60,8 @@ void TranslateUsingValueFactory(ITranslator translator, ref T objectToTranslate) public static void Translate( this ITranslator translator, ref List list, - NodePacketValueFactory valueFactory) where T : class, ITranslatable + NodePacketValueFactory valueFactory) + where T : class, ITranslatable { translator.Translate(ref list, AdaptFactory(valueFactory)); } @@ -67,7 +70,9 @@ public static void Translate( this ITranslator translator, ref IList list, NodePacketValueFactory valueFactory, - NodePacketCollectionCreator collectionFactory) where L : IList where T : ITranslatable + NodePacketCollectionCreator collectionFactory) + where L : IList + where T : ITranslatable { translator.Translate(ref list, AdaptFactory(valueFactory), collectionFactory); } @@ -75,7 +80,8 @@ public static void Translate( public static void TranslateArray( this ITranslator translator, ref T[] array, - NodePacketValueFactory valueFactory) where T : class, ITranslatable + NodePacketValueFactory valueFactory) + where T : class, ITranslatable { translator.TranslateArray(ref array, AdaptFactory(valueFactory)); } @@ -84,7 +90,8 @@ public static void TranslateDictionary( this ITranslator translator, ref Dictionary dictionary, IEqualityComparer comparer, - NodePacketValueFactory valueFactory) where T : class, ITranslatable + NodePacketValueFactory valueFactory) + where T : class, ITranslatable { translator.TranslateDictionary(ref dictionary, comparer, AdaptFactory(valueFactory)); } @@ -114,7 +121,8 @@ public static void TranslateHashSet( this ITranslator translator, ref HashSet hashSet, NodePacketValueFactory valueFactory, - NodePacketCollectionCreator> collectionFactory) where T : class, ITranslatable + NodePacketCollectionCreator> collectionFactory) + where T : class, ITranslatable { if (!translator.TranslateNullable(hashSet)) return; diff --git a/src/Shared/UnitTests/TestEnvironment.cs b/src/Shared/UnitTests/TestEnvironment.cs index bbc969855dd..43d7fa6e47b 100644 --- a/src/Shared/UnitTests/TestEnvironment.cs +++ b/src/Shared/UnitTests/TestEnvironment.cs @@ -99,7 +99,8 @@ private void Cleanup() /// Evaluate the test with the given invariant. /// /// Test invariant to assert unchanged on completion. - public T WithInvariant(T invariant) where T : TestInvariant + public T WithInvariant(T invariant) + where T : TestInvariant { _invariants.Add(invariant); return invariant; @@ -109,7 +110,8 @@ public T WithInvariant(T invariant) where T : TestInvariant /// Evaluate the test with the given transient test state. /// /// Test state to revert on completion. - public T WithTransientTestState(T transientState) where T : TransientTestState + public T WithTransientTestState(T transientState) + where T : TransientTestState { _variants.Add(transientState); return transientState; diff --git a/src/Tasks/RCWForCurrentContext.cs b/src/Tasks/RCWForCurrentContext.cs index 690f8d9773b..a3fa418ebb5 100644 --- a/src/Tasks/RCWForCurrentContext.cs +++ b/src/Tasks/RCWForCurrentContext.cs @@ -15,7 +15,8 @@ namespace Microsoft.Build.Tasks.InteropUtilities /// cache marshalled pointers for an RCW created in the current context. /// /// Type of the RCW object - internal class RCWForCurrentContext : IDisposable where T : class + internal class RCWForCurrentContext : IDisposable + where T : class { /// /// The last RCW that was created for the current context.