Skip to content
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

SA1127 Generic type constraints should be on their own line #7267

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Common.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public bool GetOrCreate<LinkType, SourceType>(SourceType source, object context,
return GetOrCreate(source.Key, source, context, out linked, slow);
}

public bool GetOrCreate<LinkType, SourceType>(KeyType key, SourceType source, object context, out LinkType linked, bool slow = false) where LinkType : LinkedObject<SourceType>, new()
public bool GetOrCreate<LinkType, SourceType>(KeyType key, SourceType source, object context, out LinkType linked, bool slow = false)
where LinkType : LinkedObject<SourceType>, new()
{
if (source == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,8 @@ internal void ResetProcessedBuildEvent()
#endregion
}

private class EventArgsEqualityComparer<T> : IEqualityComparer<T> where T : BuildEventArgs
private class EventArgsEqualityComparer<T> : IEqualityComparer<T>
where T : BuildEventArgs
{
public bool Equals(T x, T y)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,8 @@ private static void LogDeferredMessages(ILoggingService loggingService, IEnumera
/// Ensures that the packet type matches the expected type
/// </summary>
/// <typeparam name="I">The instance-type of packet being expected</typeparam>
private static I ExpectPacketType<I>(INodePacket packet, NodePacketType expectedType) where I : class, INodePacket
private static I ExpectPacketType<I>(INodePacket packet, NodePacketType expectedType)
where I : class, INodePacket
{
I castPacket = packet as I;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,9 @@ private static List<string> GetItemSpecsFromItemVectors(ItemVectorPartitionColle
/// <param name="commonKeys"></param>
/// <param name="uniqueKeysInH1"></param>
/// <param name="uniqueKeysInH2"></param>
private static void DiffHashtables<K, V>(IDictionary<K, V> h1, IDictionary<K, V> h2, out List<K> commonKeys, out List<K> uniqueKeysInH1, out List<K> uniqueKeysInH2) where K : class, IEquatable<K> where V : class
private static void DiffHashtables<K, V>(IDictionary<K, V> h1, IDictionary<K, V> h2, out List<K> commonKeys, out List<K> uniqueKeysInH1, out List<K> uniqueKeysInH2)
where K : class, IEquatable<K>
where V : class
{
commonKeys = new List<K>();
uniqueKeysInH1 = new List<K>();
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Collections/ConcurrentQueueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal static class ConcurrentQueueExtensions
/// The dequeue method.
/// </summary>
/// <typeparam name="T">The type contained within the queue</typeparam>
public static T Dequeue<T>(this ConcurrentQueue<T> stack) where T : class
public static T Dequeue<T>(this ConcurrentQueue<T> stack)
where T : class
{
ErrorUtilities.VerifyThrow(stack.TryDequeue(out T result), "Unable to dequeue from queue");
return result;
Expand Down
6 changes: 4 additions & 2 deletions src/Build/Collections/ConcurrentStackExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal static class ConcurrentStackExtensions
/// The peek method.
/// </summary>
/// <typeparam name="T">The type contained within the stack.</typeparam>
public static T Peek<T>(this ConcurrentStack<T> stack) where T : class
public static T Peek<T>(this ConcurrentStack<T> stack)
where T : class
{
ErrorUtilities.VerifyThrow(stack.TryPeek(out T result), "Unable to peek from stack");
return result;
Expand All @@ -27,7 +28,8 @@ public static T Peek<T>(this ConcurrentStack<T> stack) where T : class
/// The pop method.
/// </summary>
/// <typeparam name="T">The type contained within the stack.</typeparam>
public static T Pop<T>(this ConcurrentStack<T> stack) where T : class
public static T Pop<T>(this ConcurrentStack<T> stack)
where T : class
{
ErrorUtilities.VerifyThrow(stack.TryPop(out T result), "Unable to pop from stack");
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.Build.Collections
/// Debug view for HashSet
/// </summary>
/// <typeparam name="T"></typeparam>
internal class HashSetDebugView<T> where T : class, IKeyed
internal class HashSetDebugView<T>
where T : class, IKeyed
{
private readonly RetrievableEntryHashSet<T> _set;

Expand Down
3 changes: 2 additions & 1 deletion src/Build/Evaluation/IItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace Microsoft.Build.Evaluation
/// This interface represents an object which can act as a source of items for the Expander.
/// </summary>
/// <typeparam name="T">The type of items provided by the implementation.</typeparam>
internal interface IItemProvider<T> where T : IItem
internal interface IItemProvider<T>
where T : IItem
{
/// <summary>
/// Returns a list of items with the specified item type.
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Evaluation/IPropertyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Microsoft.Build.Evaluation
/// An interface representing an object which can provide properties to the Expander.
/// </summary>
/// <typeparam name="T">The type of properties provided.</typeparam>
internal interface IPropertyProvider<T> where T : class
internal interface IPropertyProvider<T>
where T : class
{
/// <summary>
/// Returns a property with the specified name, or null if it was not found.
Expand Down
4 changes: 3 additions & 1 deletion src/Build/Evaluation/ItemSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ public override IEnumerable<string> GetReferencedItems()
/// </summary>
/// <typeparam name="P">Property type</typeparam>
/// <typeparam name="I">Item type</typeparam>
internal sealed class MetadataTrie<P, I> where P : class, IProperty where I : class, IItem, IMetadataTable
internal sealed class MetadataTrie<P, I>
where P : class, IProperty
where I : class, IItem, IMetadataTable
{
private readonly Dictionary<string, MetadataTrie<P, I>> _children;
private readonly Func<string, string> _normalize;
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Instance/ProjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,8 @@ private static ObjectModel.ReadOnlyDictionary<string, TValue> CreateCloneDiction
/// </summary>
/// <typeparam name="TValue">The value stored in the dictionary</typeparam>
/// <param name="dictionary">Dictionary to clone.</param>
private static IDictionary<string, TValue> CreateCloneDictionary<TValue>(IDictionary<string, TValue> dictionary) where TValue : class, IKeyed
private static IDictionary<string, TValue> CreateCloneDictionary<TValue>(IDictionary<string, TValue> dictionary)
where TValue : class, IKeyed
{
if (dictionary == null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ public static int FastCountOrZero(this IEnumerable enumerable)
/// <summary>
/// Extension to IEnumerable of KVP of string, something to just return the somethings.
/// </summary>
public static IEnumerable<T> Values<T>(this IEnumerable<KeyValuePair<string, T>> source) where T : class, IKeyed
public static IEnumerable<T> Values<T>(this IEnumerable<KeyValuePair<string, T>> source)
where T : class, IKeyed
{
foreach (var entry in source)
{
Expand Down
12 changes: 8 additions & 4 deletions src/Shared/BinaryTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ public void Translate<T>(ref List<T> list, ObjectTranslator<T> objectTranslator)
list = (List<T>) listAsInterface;
}

public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : IList<T>
public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : IList<T>
{
if (!TranslateNullable(list))
{
Expand All @@ -313,7 +314,8 @@ public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTransla
/// <param name="collectionFactory">The factory to create the ICollection.</param>
/// <typeparam name="T">The type contained in the collection.</typeparam>
/// <typeparam name="L">The type of collection to be created.</typeparam>
public void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : ICollection<T>
public void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : ICollection<T>
{
if (!TranslateNullable(collection))
{
Expand Down Expand Up @@ -931,7 +933,8 @@ public void Translate<T>(ref List<T> list, ObjectTranslator<T> objectTranslator)
/// <param name="collectionFactory">factory to create the IList</param>
/// <typeparam name="T">A TaskItemType</typeparam>
/// <typeparam name="L">IList subtype</typeparam>
public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : IList<T>
public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : IList<T>
{
if (!TranslateNullable(list))
{
Expand All @@ -956,7 +959,8 @@ public void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTransla
/// <param name="collectionFactory">The factory to create the ICollection.</param>
/// <typeparam name="T">The type contained in the collection.</typeparam>
/// <typeparam name="L">The type of collection to be created.</typeparam>
public void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : ICollection<T>
public void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : ICollection<T>
{
if (!TranslateNullable(collection))
{
Expand Down
6 changes: 4 additions & 2 deletions src/Shared/ITranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ BinaryWriter Writer
/// <typeparam name="T">An ITranslatable subtype</typeparam>
/// <typeparam name="L">An IList subtype</typeparam>
/// <param name="collectionFactory">factory to create a collection</param>
void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : IList<T>;
void Translate<T, L>(ref IList<T> list, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : IList<T>;

/// <summary>
/// Translates a collection of T into the specified type using an <see cref="ObjectTranslator{T}"/> and <see cref="NodePacketCollectionCreator{L}"/>
Expand All @@ -190,7 +191,8 @@ BinaryWriter Writer
/// <param name="collectionFactory">The factory to create the ICollection.</param>
/// <typeparam name="T">The type contained in the collection.</typeparam>
/// <typeparam name="L">The type of collection to be created.</typeparam>
void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory) where L : ICollection<T>;
void Translate<T, L>(ref ICollection<T> collection, ObjectTranslator<T> objectTranslator, NodePacketCollectionCreator<L> collectionFactory)
where L : ICollection<T>;

/// <summary>
/// Translates a DateTime.
Expand Down
3 changes: 2 additions & 1 deletion src/Shared/NGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Microsoft.Build.Shared
/// It works because although this is a value type, it is not defined in mscorlib.
/// </comment>
/// <typeparam name="T">Wrapped type</typeparam>
internal struct NGen<T> where T : struct
internal struct NGen<T>
where T : struct
{
/// <summary>
/// Wrapped value
Expand Down
22 changes: 15 additions & 7 deletions src/Shared/TranslatorHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal static class TranslatorHelpers
public static void Translate<T>(
this ITranslator translator,
ref T instance,
NodePacketValueFactory<T> valueFactory) where T : ITranslatable
NodePacketValueFactory<T> valueFactory)
where T : ITranslatable
{
if (!translator.TranslateNullable(instance))
{
Expand All @@ -45,7 +46,8 @@ public static void Translate<T>(
}
}

static ObjectTranslator<T> AdaptFactory<T>(NodePacketValueFactory<T> valueFactory) where T : ITranslatable
static ObjectTranslator<T> AdaptFactory<T>(NodePacketValueFactory<T> valueFactory)
where T : ITranslatable
{
void TranslateUsingValueFactory(ITranslator translator, ref T objectToTranslate)
{
Expand All @@ -58,7 +60,8 @@ void TranslateUsingValueFactory(ITranslator translator, ref T objectToTranslate)
public static void Translate<T>(
this ITranslator translator,
ref List<T> list,
NodePacketValueFactory<T> valueFactory) where T : class, ITranslatable
NodePacketValueFactory<T> valueFactory)
where T : class, ITranslatable
{
translator.Translate(ref list, AdaptFactory(valueFactory));
}
Expand All @@ -67,15 +70,18 @@ public static void Translate<T, L>(
this ITranslator translator,
ref IList<T> list,
NodePacketValueFactory<T> valueFactory,
NodePacketCollectionCreator<L> collectionFactory) where L : IList<T> where T : ITranslatable
NodePacketCollectionCreator<L> collectionFactory)
where L : IList<T>
where T : ITranslatable
{
translator.Translate(ref list, AdaptFactory(valueFactory), collectionFactory);
}

public static void TranslateArray<T>(
this ITranslator translator,
ref T[] array,
NodePacketValueFactory<T> valueFactory) where T : class, ITranslatable
NodePacketValueFactory<T> valueFactory)
where T : class, ITranslatable
{
translator.TranslateArray(ref array, AdaptFactory(valueFactory));
}
Expand All @@ -84,7 +90,8 @@ public static void TranslateDictionary<T>(
this ITranslator translator,
ref Dictionary<string, T> dictionary,
IEqualityComparer<string> comparer,
NodePacketValueFactory<T> valueFactory) where T : class, ITranslatable
NodePacketValueFactory<T> valueFactory)
where T : class, ITranslatable
{
translator.TranslateDictionary(ref dictionary, comparer, AdaptFactory(valueFactory));
}
Expand Down Expand Up @@ -114,7 +121,8 @@ public static void TranslateHashSet<T>(
this ITranslator translator,
ref HashSet<T> hashSet,
NodePacketValueFactory<T> valueFactory,
NodePacketCollectionCreator<HashSet<T>> collectionFactory) where T : class, ITranslatable
NodePacketCollectionCreator<HashSet<T>> collectionFactory)
where T : class, ITranslatable
{
if (!translator.TranslateNullable(hashSet))
return;
Expand Down
6 changes: 4 additions & 2 deletions src/Shared/UnitTests/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private void Cleanup()
/// Evaluate the test with the given invariant.
/// </summary>
/// <param name="invariant">Test invariant to assert unchanged on completion.</param>
public T WithInvariant<T>(T invariant) where T : TestInvariant
public T WithInvariant<T>(T invariant)
where T : TestInvariant
{
_invariants.Add(invariant);
return invariant;
Expand All @@ -109,7 +110,8 @@ public T WithInvariant<T>(T invariant) where T : TestInvariant
/// Evaluate the test with the given transient test state.
/// </summary>
/// <returns>Test state to revert on completion.</returns>
public T WithTransientTestState<T>(T transientState) where T : TransientTestState
public T WithTransientTestState<T>(T transientState)
where T : TransientTestState
{
_variants.Add(transientState);
return transientState;
Expand Down
3 changes: 2 additions & 1 deletion src/Tasks/RCWForCurrentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Microsoft.Build.Tasks.InteropUtilities
/// cache marshalled pointers for an RCW created in the current context.
/// </summary>
/// <typeparam name="T">Type of the RCW object</typeparam>
internal class RCWForCurrentContext<T> : IDisposable where T : class
internal class RCWForCurrentContext<T> : IDisposable
where T : class
{
/// <summary>
/// The last RCW that was created for the current context.
Expand Down