Skip to content

Commit

Permalink
chore: align analyzers across repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Apr 29, 2024
1 parent 5e446fb commit c86b095
Show file tree
Hide file tree
Showing 86 changed files with 843 additions and 748 deletions.
340 changes: 263 additions & 77 deletions .editorconfig

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static async Task<ITestApplicationBuilder> CreateBuilderAsync(string[] ar
string[] args)
{
// Log useful information
var version = (AssemblyInformationalVersionAttribute?)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute));
AssemblyInformationalVersionAttribute? version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (version is not null)
{
await logger.LogInformationAsync($"Version: {version.InformationalVersion}");
Expand Down Expand Up @@ -299,7 +299,11 @@ 4 Default(TestResults in the current working folder)

if (result.TryGetOptionArgumentList(PlatformCommandLineProvider.DiagnosticVerbosityOptionKey, out string[]? verbosity))
{
#if NET
logLevel = Enum.Parse<LogLevel>(verbosity[0], true);
#else
logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), verbosity[0], true);
#endif
}

// Override the log level if the environment variable is set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ public override bool Equals(object? obj)
=> obj is ArgumentArity argumentArity && Equals(argumentArity);

/// <inheritdoc/>
public override int GetHashCode()
{
public override int GetHashCode() =>
#if NET
return HashCode.Combine(Min, Max);
HashCode.Combine(Min, Max);
#else
return Min.GetHashCode() ^ Max.GetHashCode();
Min.GetHashCode() ^ Max.GetHashCode();
#endif
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public async Task<(bool IsValid, string? ValidationError)> TryParseAndValidateAs
return (false, arityErrors);
}

var optionsResult = await ValidateOptionsArgumentsAsync();
ValidationResult optionsResult = await ValidateOptionsArgumentsAsync();
if (!optionsResult.IsValid)
{
return (false, optionsResult.ErrorMessage);
}

var configurationResult = await ValidateConfigurationAsync();
ValidationResult configurationResult = await ValidateConfigurationAsync();
#pragma warning disable IDE0046 // Convert to conditional expression - make the code less readable
if (!configurationResult.IsValid)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ private async Task<ValidationResult> ValidateConfigurationAsync()
StringBuilder? stringBuilder = null;
foreach (ICommandLineOptionsProvider commandLineOptionsProvider in _systemCommandLineOptionsProviders.Union(ExtensionsCommandLineOptionsProviders))
{
var result = await commandLineOptionsProvider.ValidateCommandLineOptionsAsync(this);
ValidationResult result = await commandLineOptionsProvider.ValidateCommandLineOptionsAsync(this);
if (!result.IsValid)
{
stringBuilder ??= new();
Expand All @@ -161,7 +161,7 @@ private async Task<ValidationResult> ValidateOptionsArgumentsAsync()
foreach (OptionRecord optionRecord in _parseResult.Options)
{
ICommandLineOptionsProvider extension = GetAllCommandLineOptionsProviderByOptionName(optionRecord.Option).Single();
var result = await extension.ValidateOptionArgumentsAsync(extension.GetCommandLineOptions().Single(x => x.Name == optionRecord.Option), optionRecord.Arguments);
ValidationResult result = await extension.ValidateOptionArgumentsAsync(extension.GetCommandLineOptions().Single(x => x.Name == optionRecord.Option), optionRecord.Arguments);
if (!result.IsValid)
{
stringBuilder ??= new();
Expand Down Expand Up @@ -448,7 +448,7 @@ async Task DisplayPlatformInfoAsync()
await _platformOutputDevice.DisplayAsync(this, new TextOutputDeviceData("Microsoft Testing Platform:"));

// TODO: Replace Assembly with IAssembly
var version = (AssemblyInformationalVersionAttribute?)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute));
AssemblyInformationalVersionAttribute? version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
string versionInfo = version?.InformationalVersion ?? "Not Available";
await _platformOutputDevice.DisplayAsync(this, new TextOutputDeviceData($" Version: {versionInfo}"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public static (Dictionary<string, string?> SingleValueData, Dictionary<string, s

private (Dictionary<string, string?> SingleValueData, Dictionary<string, string?> PropertyToAllChildren) ParseStream(Stream input)
{
var jsonDocumentOptions = new JsonDocumentOptions
JsonDocumentOptions jsonDocumentOptions = new()
{
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};

using (var reader = new StreamReader(input))
using (StreamReader reader = new(input))
using (var doc = JsonDocument.Parse(reader.ReadToEnd(), jsonDocumentOptions))
{
if (doc.RootElement.ValueKind != JsonValueKind.Object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static (Dictionary<string, string?> SingleValueData, Dictionary<string, s

private (Dictionary<string, string?> SingleValueData, Dictionary<string, string?> PropertyToAllChildren) ParseStream(Stream input)
{
using var reader = new StreamReader(input);
using StreamReader reader = new(input);
var doc = (JsonObject)Jsonite.Json.Deserialize(reader.ReadToEnd(), _settings);
if (doc is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static async Task<bool> WaitAsync(this CountdownEvent countdownEvent, u
CancellationTokenRegistration tokenRegistration = default;
try
{
var tcs = new TaskCompletionSource<bool>();
TaskCompletionSource<bool> tcs = new();

// https://learn.microsoft.com/dotnet/api/system.threading.threadpool.registerwaitforsingleobject?view=net-7.0
#pragma warning disable SA1115 // Parameter should follow comma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static async Task WithCancellationAsync(this Task task, CancellationToken
throw new TimeoutException(CreateMessage(timeout, filePath, lineNumber));
}
#else
var cts = new CancellationTokenSource();
CancellationTokenSource cts = new();
if (task == await Task.WhenAny(task, Task.Delay(timeout, cts.Token)).ConfigureAwait(false))
{
cts.Cancel();
Expand Down Expand Up @@ -174,7 +174,7 @@ public static async Task WithCancellationAsync(this Task task, CancellationToken
throw new TimeoutException(CreateMessage(timeout, filePath, lineNumber));
}
#else
var cts = new CancellationTokenSource();
CancellationTokenSource cts = new();
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, cts.Token);
if (task == await Task.WhenAny(task, Task.Delay(timeout, linkedTokenSource.Token)).ConfigureAwait(false))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static async Task DisplayAfterSessionEndRunAsync(IPlatformOutputDevice o

private static async Task NotifyTestSessionStartAsync(SessionUid sessionUid, BaseMessageBus baseMessageBus, ServiceProvider serviceProvider, CancellationToken cancellationToken)
{
var testSessionLifetimeHandlersContainer = serviceProvider.GetService<TestSessionLifetimeHandlersContainer>();
TestSessionLifetimeHandlersContainer? testSessionLifetimeHandlersContainer = serviceProvider.GetService<TestSessionLifetimeHandlersContainer>();
if (testSessionLifetimeHandlersContainer is null)
{
return;
Expand All @@ -134,7 +134,7 @@ private static async Task NotifyTestSessionEndAsync(SessionUid sessionUid, BaseM
// Drain messages generated by the test session execution before to process the session end notification.
await baseMessageBus.DrainDataAsync();

var testSessionLifetimeHandlersContainer = serviceProvider.GetService<TestSessionLifetimeHandlersContainer>();
TestSessionLifetimeHandlersContainer? testSessionLifetimeHandlersContainer = serviceProvider.GetService<TestSessionLifetimeHandlersContainer>();
if (testSessionLifetimeHandlersContainer is null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override async Task<int> InternalRunAsync()
if (telemetryInformation.IsEnabled)
{
DateTimeOffset consoleRunStop = _clock.UtcNow;
var metrics = new Dictionary<string, object>
Dictionary<string, object> metrics = new()
{
{ TelemetryProperties.HostProperties.RunStart, consoleRunStart },
{ TelemetryProperties.HostProperties.RunStop, consoleRunStop },
Expand Down
24 changes: 12 additions & 12 deletions src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override async Task<int> InternalRunAsync()
_messageHandler = await _messageHandlerFactory.CreateMessageHandlerAsync(_testApplicationCancellationTokenSource.CancellationToken);

// Initialize the ServerLoggerForwarderProvider, it can be null if diagnostic is disabled.
var serviceLoggerForwarder = ServiceProvider.GetService<ServerLoggerForwarderProvider>();
ServerLoggerForwarderProvider? serviceLoggerForwarder = ServiceProvider.GetService<ServerLoggerForwarderProvider>();
if (serviceLoggerForwarder is not null)
{
await serviceLoggerForwarder.InitializeAsync(this);
Expand Down Expand Up @@ -247,7 +247,7 @@ private async Task HandleMessagesAsync()
break;

case ErrorMessage error:
var exception = new RemoteInvocationException();
RemoteInvocationException exception = new();
CompleteRequest(ref _serverToClientRequests, error.Id, completion => completion.TrySetException(exception));
break;
default:
Expand Down Expand Up @@ -332,7 +332,7 @@ private async Task HandleRequestAsync(RequestMessage request, CancellationToken
{
// We enqueue the request before to "unlink" the current thread so we're sure that we
// correctly handle the completion also after the "exit"
var rpcState = new RpcInvocationState();
RpcInvocationState rpcState = new();
_clientToServerRequests.TryAdd(request.Id, rpcState);

// Note: Yield, so that the main message reading loop can continue.
Expand Down Expand Up @@ -457,7 +457,7 @@ private async Task<ResponseArgsBase> ExecuteRequestAsync(RequestArgsBase args, s

// Note: Currently the request generation and filtering isn't extensible
// in server mode, we create NoOp services, so that they're always available.
var requestFactory = new ServerTestExecutionRequestFactory(session =>
ServerTestExecutionRequestFactory requestFactory = new(session =>
{
ICollection<TestNode>? testNodes = args.TestNodes;
string? filter = args.GraphFilter;
Expand All @@ -475,9 +475,9 @@ private async Task<ResponseArgsBase> ExecuteRequestAsync(RequestArgsBase args, s
});

// Build the per request objects
var filterFactory = new ServerTestExecutionFilterFactory();
var invoker = new TestHostTestFrameworkInvoker(perRequestServiceProvider);
var testNodeUpdateProcessor = new PerRequestServerDataConsumer(perRequestServiceProvider, this, args.RunId, perRequestServiceProvider.GetTask());
ServerTestExecutionFilterFactory filterFactory = new();
TestHostTestFrameworkInvoker invoker = new(perRequestServiceProvider);
PerRequestServerDataConsumer testNodeUpdateProcessor = new(perRequestServiceProvider, this, args.RunId, perRequestServiceProvider.GetTask());

DateTimeOffset adapterLoadStart = _clock.UtcNow;

Expand Down Expand Up @@ -611,7 +611,7 @@ private async Task<ResponseArgsBase> ExecuteRequestAsync(RequestArgsBase args, s
private async Task SendErrorAsync(int reqId, int errorCode, string message, object? data, CancellationToken cancellationToken)
{
AssertInitialized();
var error = new ErrorMessage(reqId, errorCode, message, data);
ErrorMessage error = new(reqId, errorCode, message, data);

using (await _messageMonitor.LockAsync(cancellationToken))
{
Expand All @@ -622,7 +622,7 @@ private async Task SendErrorAsync(int reqId, int errorCode, string message, obje
private async Task SendResponseAsync(int reqId, object result, CancellationToken cancellationToken)
{
AssertInitialized();
var response = new ResponseMessage(reqId, result);
ResponseMessage response = new(reqId, result);

using (await _messageMonitor.LockAsync(cancellationToken))
{
Expand All @@ -640,7 +640,7 @@ private async Task SendMessageAsync(string method, object? @params, Cancellation
_requestCounter.AddCount();
try
{
var notification = new NotificationMessage(method, @params);
NotificationMessage notification = new(method, @params);

using (await _messageMonitor.LockAsync(cancellationToken))
{
Expand Down Expand Up @@ -698,8 +698,8 @@ private async Task SendRequestAsync(string method, object @params, CancellationT
{
AssertInitialized();
int requestId = Interlocked.Increment(ref _serverToClientRequestId);
var request = new RequestMessage(requestId, method, @params);
var invocationState = new RpcInvocationState();
RequestMessage request = new(requestId, method, @params);
RpcInvocationState invocationState = new();

_serverToClientRequests.TryAdd(requestId, invocationState);

Expand Down

0 comments on commit c86b095

Please sign in to comment.