Skip to content

Commit 633235e

Browse files
authored
Code analysis with static analysers based on microsoft rules (#2831)
Code refactoring.
1 parent 620f420 commit 633235e

File tree

54 files changed

+115
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+115
-109
lines changed

src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ protected override void Dispose(bool disposing)
371371

372372
// Delete all the temp event log directories
373373
this.RemoveTempEventLogDirs(this.eventLogDirectories);
374-
GC.SuppressFinalize(this);
375374
}
376375

377376
#endregion

src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public static partial class ManagedNameHelper
2424
/// A <see cref="MethodBase" /> instance to get fully qualified managed type and method name.
2525
/// </param>
2626
/// <param name="managedTypeName">
27-
/// When this method returns, contains the fully qualified managed type name of the <paramref name="method"/>.
27+
/// When this method returns, contains the fully qualified managed type name of the <paramref name="method"/>.
2828
/// This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
2929
/// The format is defined in <see href="https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md#managedtype-property">the RFC</see>.
3030
/// </param>
3131
/// <param name="managedMethodName">
32-
/// When this method returns, contains the fully qualified managed method name of the <paramref name="method"/>.
32+
/// When this method returns, contains the fully qualified managed method name of the <paramref name="method"/>.
3333
/// This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
3434
/// The format is defined in <see href="https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md#managedmethod-property">the RFC</see>.
3535
/// </param>
@@ -43,7 +43,7 @@ public static partial class ManagedNameHelper
4343
/// Required functionality on <paramref name="method"/> is missing on the current platform.
4444
/// </exception>
4545
/// <remarks>
46-
/// More information about <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/> can be found in
46+
/// More information about <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/> can be found in
4747
/// <see href="https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md">the RFC</see>.
4848
/// </remarks>
4949
public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName)
@@ -65,7 +65,7 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
6565
// sure we are working with the open form of the generic type.
6666
semanticType = semanticType.GetGenericTypeDefinition();
6767

68-
// The method might have some of its parameters specified by the original closed type
68+
// The method might have some of its parameters specified by the original closed type
6969
// declaration. Here we use the method handle (basically metadata token) to create
7070
// a new method reference using the open form of the reflected type. The intent is
7171
// to strip all generic type parameters.
@@ -114,7 +114,7 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
114114
}
115115

116116
/// <summary>
117-
/// Gets the <see cref="MethodBase"/> object with the specified <paramref name="managedTypeName"/>
117+
/// Gets the <see cref="MethodBase"/> object with the specified <paramref name="managedTypeName"/>
118118
/// and <paramref name="managedMethodName"/> in the <paramref name="assembly"/> instance.
119119
/// </summary>
120120
/// <param name="assembly">
@@ -132,11 +132,11 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
132132
/// A <see cref="MethodBase" /> object that represents specified parameters, throws if null.
133133
/// </returns>
134134
/// <exception cref="InvalidManagedNameException">
135-
/// Values specified with <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/>
135+
/// Values specified with <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/>
136136
/// does not correspond to a method in the <paramref name="assembly"/> instance, or malformed.
137137
/// </exception>
138138
/// <remarks>
139-
/// More information about <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/> can be found in
139+
/// More information about <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/> can be found in
140140
/// <see href="https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md">the RFC</see>.
141141
/// </remarks>
142142
public static MethodBase GetMethod(Assembly assembly, string managedTypeName, string managedMethodName)
@@ -335,7 +335,7 @@ private static void AppendMethodString(StringBuilder methodBuilder, string name,
335335

336336
private static void NormalizeAndAppendString(StringBuilder b, string name)
337337
{
338-
b.Append("'");
338+
b.Append('\'');
339339
for (int i = 0; i < name.Length; i++)
340340
{
341341
char c = name[i];
@@ -348,15 +348,15 @@ private static void NormalizeAndAppendString(StringBuilder b, string name)
348348
// b.Append('0', 4 - encoded.Length);
349349
// b.Append(encoded);
350350

351-
b.Append("\\");
351+
b.Append('\\');
352352
b.Append(c);
353353
continue;
354354
}
355355
}
356356

357357
b.Append(c);
358358
}
359-
b.Append("'");
359+
b.Append('\'');
360360
}
361361

362362
private static int AppendNestedTypeName(StringBuilder b, Type type)
@@ -439,7 +439,7 @@ private static bool NeedsEscaping(char c, int pos)
439439
}
440440

441441
if (c == '_'
442-
|| char.IsLetterOrDigit(c) // Lu, Ll, Lt, Lm, Lo, or Nl
442+
|| char.IsLetterOrDigit(c) // Lu, Ll, Lt, Lm, Lo, or Nl
443443
)
444444
{
445445
return false;

src/Microsoft.TestPlatform.Build/ArgumentEscaper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static string HandleEscapeSequenceInArgForProcessStart(string arg)
2323

2424
if (needsQuotes)
2525
{
26-
sb.Append("\"");
26+
sb.Append('\"');
2727
}
2828

2929
for (int i = 0; i < arg.Length; ++i)
@@ -70,7 +70,7 @@ public static string HandleEscapeSequenceInArgForProcessStart(string arg)
7070

7171
if (needsQuotes)
7272
{
73-
sb.Append("\"");
73+
sb.Append('\"');
7474
}
7575

7676
return sb.ToString();

src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryComplete
267267
// Raise onDiscoveredTests event if there are some tests in the last chunk.
268268
// (We don't want to send the tests in the discovery complete event so that programming on top of
269269
// RS client is easier i.e. user does not have to listen on discovery complete event.)
270-
if (lastChunk != null && lastChunk.Count() > 0)
270+
if (lastChunk != null && lastChunk.Any())
271271
{
272272
var discoveredTestsEvent = new DiscoveredTestsEventArgs(lastChunk);
273273
this.LoggerManager.HandleDiscoveredTests(discoveredTestsEvent);

src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static T CreateTestExtension<T>(Type extensionType)
6969
{
7070
if (extensionType == null)
7171
{
72-
throw new ArgumentNullException("extensionType");
72+
throw new ArgumentNullException(nameof(extensionType));
7373
}
7474

7575
EqtTrace.Info("TestPluginManager.CreateTestExtension: Attempting to load test extension: " + extensionType);

src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal void RaiseTestRunMessage(TestRunMessageEventArgs args)
177177
{
178178
if (args == null)
179179
{
180-
throw new ArgumentNullException("args");
180+
throw new ArgumentNullException(nameof(args));
181181
}
182182

183183
this.CheckDisposed();

src/Microsoft.TestPlatform.Common/Logging/TestSessionMessageLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void SendMessage(TestMessageLevel testMessageLevel, string message)
6464
{
6565
if (string.IsNullOrWhiteSpace(message))
6666
{
67-
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, "message");
67+
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, nameof(message));
6868
}
6969

7070
if (this.TreatTestAdapterErrorsAsWarnings

src/Microsoft.TestPlatform.Common/RunSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ISettingsProvider GetSettings(string settingsName)
6969
{
7070
if (StringUtilities.IsNullOrWhiteSpace(settingsName))
7171
{
72-
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, "settingsName");
72+
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, nameof(settingsName));
7373
}
7474

7575
// Try and lookup the settings provider.

src/Microsoft.TestPlatform.Common/SettingsProvider/SettingsProviderExtensionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ internal LazyExtension<ISettingsProvider, ISettingsProviderCapabilities> GetSett
181181
{
182182
if (string.IsNullOrWhiteSpace(settingsName))
183183
{
184-
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, "settingsName");
184+
throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, nameof(settingsName));
185185
}
186186

187187
this.SettingsProvidersMap.TryGetValue(settingsName, out LazyExtension<ISettingsProvider, ISettingsProviderCapabilities> settingsProvider);

src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void Dispose()
8181
EqtTrace.Verbose("LengthPrefixCommunicationChannel.Dispose: Dispose reader and writer.");
8282
this.reader.Dispose();
8383
this.writer.Dispose();
84+
GC.SuppressFinalize(this);
8485
}
8586
}
8687
}

0 commit comments

Comments
 (0)