From 242f7b1883543f986d097667d08f361470f47b4e Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 12 Aug 2019 16:45:34 -0400 Subject: [PATCH] Enable StyleCop rules 1205, 1411, 1026, and 1000 (dotnet/corefxdotnet/coreclr#40254) * Fix StyleCop warning SA1411 (attribute ctor shouldn't use unnecessary parens) * Fix StyleCop warning SA1026 (new[] spacing) * Fix StyleCop warning SA1000 (consistent spacing around if, for, switch, etc.) * Fix StyleCop warning SA1205 (partial elements should declare an access modifier) Signed-off-by: dotnet-bot Commit migrated from https://github.com/dotnet/coreclr/commit/6015c8415f42c73a12292f73214875ca3864d12d --- src/libraries/System.Private.CoreLib/src/CodeAnalysis.ruleset | 4 ---- .../System.Private.CoreLib/src/System/Decimal.DecCalc.cs | 2 +- .../src/System/Diagnostics/Tracing/CounterGroup.cs | 2 +- .../src/System/Diagnostics/Tracing/EventCounter.cs | 2 +- .../src/System/Diagnostics/Tracing/EventSource.cs | 8 ++++---- .../src/System/Diagnostics/Tracing/StubEnvironment.cs | 4 ++-- .../System/Diagnostics/Tracing/TraceLogging/EventPayload.cs | 2 +- .../src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs | 2 +- .../Tracing/TraceLogging/TraceLoggingEventSource.cs | 4 ++-- .../System.Private.CoreLib/src/System/ParseNumbers.cs | 2 +- .../System.Private.CoreLib/src/System/Text/StringBuilder.cs | 4 ++-- .../System.Private.CoreLib/src/System/Threading/Tasks/Task.cs | 6 +++--- .../src/System/Threading/Tasks/TaskFactory.cs | 10 +++++----- .../System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs | 2 +- 14 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/CodeAnalysis.ruleset b/src/libraries/System.Private.CoreLib/src/CodeAnalysis.ruleset index 67b7b14..9bf5d68 100644 --- a/src/libraries/System.Private.CoreLib/src/CodeAnalysis.ruleset +++ b/src/libraries/System.Private.CoreLib/src/CodeAnalysis.ruleset @@ -75,7 +75,6 @@ - @@ -92,7 +91,6 @@ - @@ -127,7 +125,6 @@ - @@ -153,7 +150,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs index 8b9286f..1910536 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs @@ -690,7 +690,7 @@ PosRem: } break; - } // for(;;) + } // for (;;) } return scale; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs index 08c50a4..3f023cc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs @@ -65,7 +65,7 @@ namespace System.Diagnostics.Tracing } else if (e.Command == EventCommand.Disable) { - lock(s_counterGroupLock) + lock (s_counterGroupLock) { DisableTimer(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs index 854c6f6..2cc42d7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs @@ -116,7 +116,7 @@ namespace System.Diagnostics.Tracing internal void ResetStatistics() { - lock(this) + lock (this) { _count = 0; _sum = 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index df40519..b8d3142 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -691,7 +691,7 @@ namespace System.Diagnostics.Tracing { // If the EventSource is set to emit all events as TraceLogging events, skip this initialization. // Events will be defined when they are emitted for the first time. - if(SelfDescribingEvents) + if (SelfDescribingEvents) { return; } @@ -1874,7 +1874,7 @@ namespace System.Diagnostics.Tracing // ETW strings are NULL-terminated, so marshal everything up to the first // null in the string. //return System.Runtime.InteropServices.Marshal.PtrToStringUni(dataPointer); - if(dataPointer == IntPtr.Zero) + if (dataPointer == IntPtr.Zero) { return null; } @@ -2524,7 +2524,7 @@ namespace System.Diagnostics.Tracing private int GetParameterCount(EventMetadata eventData) { int paramCount; - if(eventData.Parameters == null) + if (eventData.Parameters == null) { paramCount = eventData.ParameterTypes.Length; } @@ -2539,7 +2539,7 @@ namespace System.Diagnostics.Tracing private Type GetDataType(EventMetadata eventData, int parameterId) { Type dataType; - if(eventData.Parameters == null) + if (eventData.Parameters == null) { dataType = EventTypeToType(eventData.ParameterTypes[parameterId]); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs index 7dcfbf1..05b9feb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs @@ -310,7 +310,7 @@ namespace Microsoft.Reflection public static Type? GetNestedType(this Type type, string nestedTypeName) { TypeInfo? ti = null; - foreach(var nt in type.GetTypeInfo().DeclaredNestedTypes) + foreach (var nt in type.GetTypeInfo().DeclaredNestedTypes) { if (nt.Name == nestedTypeName) { @@ -362,7 +362,7 @@ namespace Microsoft.Reflection #if ES_BUILD_STANDALONE internal static partial class Interop { - [SuppressUnmanagedCodeSecurityAttribute()] + [SuppressUnmanagedCodeSecurityAttribute] internal static partial class Kernel32 { [DllImport("kernel32.dll", CharSet = CharSet.Auto)] diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs index a327708..9416d50 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs @@ -46,7 +46,7 @@ namespace System.Diagnostics.Tracing throw new System.ArgumentNullException(nameof(key)); int position = 0; - foreach(var name in m_names) + foreach (var name in m_names) { if (name == key) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs index 5ed20f2..2a95a7d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs @@ -26,7 +26,7 @@ namespace System.Diagnostics.Tracing /// internal static void ReserveEventIDsBelow(int eventId) { - for(;;) + for (;;) { int snapshot = lastIdentity; int newIdentity = (lastIdentity & ~0xFFFFFF) + eventId; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index 57f2637..e6b9265 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -436,7 +436,7 @@ namespace System.Diagnostics.Tracing var pinCount = eventTypes.pinCount; var scratch = stackalloc byte[eventTypes.scratchSize]; var descriptors = stackalloc EventData[eventTypes.dataCount + 3]; - for(int i = 0; i < eventTypes.dataCount + 3; i++) + for (int i = 0; i < eventTypes.dataCount + 3; i++) descriptors[i] = default; var pins = stackalloc GCHandle[pinCount]; @@ -552,7 +552,7 @@ namespace System.Diagnostics.Tracing // we may have 2 for each arg, so we allocate enough for this. var descriptorsLength = eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3; var descriptors = stackalloc EventData[descriptorsLength]; - for(int i = 0; i < descriptorsLength; i++) + for (int i = 0; i < descriptorsLength; i++) descriptors[i] = default; fixed (byte* diff --git a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs index 0978186..7d0b58e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs @@ -262,7 +262,7 @@ namespace System else { index = 0; - for (int i = 0; i < buffer.Length; i++) // for(...;i diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 7257d9a..11ebc1c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -4883,11 +4883,11 @@ namespace System.Threading.Tasks // A ManualResetEventSlim that will get Set after Invoke is called count times. // This allows us to replace this logic: // var mres = new ManualResetEventSlim(tasks.Count); - // Action completionAction = delegate { if(Interlocked.Decrement(ref count) == 0) mres.Set(); }; - // foreach(var task in tasks) task.AddCompletionAction(completionAction); + // Action completionAction = delegate { if (Interlocked.Decrement(ref count) == 0) mres.Set(); }; + // foreach (var task in tasks) task.AddCompletionAction(completionAction); // with this logic: // var mres = new SetOnCountdownMres(tasks.Count); - // foreach(var task in tasks) task.AddCompletionAction(mres); + // foreach (var task in tasks) task.AddCompletionAction(mres); // which saves a couple of allocations. // // Used in WaitAllBlockingCore (above). diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory.cs index af549d0..300e17e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory.cs @@ -1541,12 +1541,12 @@ namespace System.Threading.Tasks // it has been invoked N times. This allows us to replace this logic: // Task promise = new Task(...); // int _count = tasksCopy.Length; - // Action completionAction = delegate {if(Interlocked.Decrement(ref _count) == 0) promise.TrySetResult(tasksCopy); - // for(int i=0; i<_count; i++) + // Action completionAction = delegate {if (Interlocked.Decrement(ref _count) == 0) promise.TrySetResult(tasksCopy); + // for (int i=0; i<_count; i++) // tasksCopy[i].AddCompletionAction(completionAction); // with this logic: // CompletionOnCountdownPromise promise = new CompletionOnCountdownPromise(tasksCopy); - // for(int i=0; i promise = new Task(...); // Action completionAction = delegate(Task completingTask) { promise.TrySetResult(completingTask); } - // for(int i=0; i