Skip to content

Commit 2efddc2

Browse files
cory-millernikola-jokic
authored andcommitted
Fix IDE0090 (actions#2211)
1 parent 1b149c2 commit 2efddc2

File tree

99 files changed

+412
-412
lines changed

Some content is hidden

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

99 files changed

+412
-412
lines changed

src/Runner.Common/ActionCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class ActionCommand
3131
new EscapeMapping(token: "%", replacement: "%25"),
3232
};
3333

34-
private readonly Dictionary<string, string> _properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
34+
private readonly Dictionary<string, string> _properties = new(StringComparer.OrdinalIgnoreCase);
3535
public const string Prefix = "##[";
3636
public const string _commandKey = "::";
3737

src/Runner.Common/ConfigurationStore.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public string RepoOrOrgName
7474
{
7575
get
7676
{
77-
Uri accountUri = new Uri(this.ServerUrl);
77+
Uri accountUri = new(this.ServerUrl);
7878
string repoOrOrgName = string.Empty;
7979

8080
if (accountUri.Host.EndsWith(".githubusercontent.com", StringComparison.OrdinalIgnoreCase))
8181
{
82-
Uri gitHubUrl = new Uri(this.GitHubUrl);
82+
Uri gitHubUrl = new(this.GitHubUrl);
8383

8484
// Use the "NWO part" from the GitHub URL path
8585
repoOrOrgName = gitHubUrl.AbsolutePath.Trim('/');

src/Runner.Common/ExtensionManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface IExtensionManager : IRunnerService
1414

1515
public sealed class ExtensionManager : RunnerService, IExtensionManager
1616
{
17-
private readonly ConcurrentDictionary<Type, List<IExtension>> _cache = new ConcurrentDictionary<Type, List<IExtension>>();
17+
private readonly ConcurrentDictionary<Type, List<IExtension>> _cache = new();
1818

1919
public List<T> GetExtensions<T>() where T : class, IExtension
2020
{

src/Runner.Common/HostContext.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public sealed class HostContext : EventListener, IObserver<DiagnosticListener>,
5151
private static int _defaultLogRetentionDays = 30;
5252
private static int[] _vssHttpMethodEventIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 24 };
5353
private static int[] _vssHttpCredentialEventIds = new int[] { 11, 13, 14, 15, 16, 17, 18, 20, 21, 22, 27, 29 };
54-
private readonly ConcurrentDictionary<Type, object> _serviceInstances = new ConcurrentDictionary<Type, object>();
55-
private readonly ConcurrentDictionary<Type, Type> _serviceTypes = new ConcurrentDictionary<Type, Type>();
54+
private readonly ConcurrentDictionary<Type, object> _serviceInstances = new();
55+
private readonly ConcurrentDictionary<Type, Type> _serviceTypes = new();
5656
private readonly ISecretMasker _secretMasker = new SecretMasker();
57-
private readonly List<ProductInfoHeaderValue> _userAgents = new List<ProductInfoHeaderValue>() { new ProductInfoHeaderValue($"GitHubActionsRunner-{BuildConstants.RunnerPackage.PackageName}", BuildConstants.RunnerPackage.Version) };
58-
private CancellationTokenSource _runnerShutdownTokenSource = new CancellationTokenSource();
59-
private object _perfLock = new object();
57+
private readonly List<ProductInfoHeaderValue> _userAgents = new() { new ProductInfoHeaderValue($"GitHubActionsRunner-{BuildConstants.RunnerPackage.PackageName}", BuildConstants.RunnerPackage.Version) };
58+
private CancellationTokenSource _runnerShutdownTokenSource = new();
59+
private object _perfLock = new();
6060
private Tracing _trace;
6161
private Tracing _actionsHttpTrace;
6262
private Tracing _netcoreHttpTrace;
@@ -66,7 +66,7 @@ public sealed class HostContext : EventListener, IObserver<DiagnosticListener>,
6666
private IDisposable _diagListenerSubscription;
6767
private StartupType _startupType;
6868
private string _perfFile;
69-
private RunnerWebProxy _webProxy = new RunnerWebProxy();
69+
private RunnerWebProxy _webProxy = new();
7070

7171
public event EventHandler Unloading;
7272
public CancellationToken RunnerShutdownToken => _runnerShutdownTokenSource.Token;

src/Runner.Common/HostTraceListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private StreamWriter CreatePageLogWriter()
164164
{
165165
if (_enableLogRetention)
166166
{
167-
DirectoryInfo diags = new DirectoryInfo(_logFileDirectory);
167+
DirectoryInfo diags = new(_logFileDirectory);
168168
var logs = diags.GetFiles($"{_logFilePrefix}*.log");
169169
foreach (var log in logs)
170170
{

src/Runner.Common/JobServerQueue.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
3939
private Guid _jobTimelineRecordId;
4040

4141
// queue for web console line
42-
private readonly ConcurrentQueue<ConsoleLineInfo> _webConsoleLineQueue = new ConcurrentQueue<ConsoleLineInfo>();
42+
private readonly ConcurrentQueue<ConsoleLineInfo> _webConsoleLineQueue = new();
4343

4444
// queue for file upload (log file or attachment)
45-
private readonly ConcurrentQueue<UploadFileInfo> _fileUploadQueue = new ConcurrentQueue<UploadFileInfo>();
45+
private readonly ConcurrentQueue<UploadFileInfo> _fileUploadQueue = new();
4646

4747
// queue for timeline or timeline record update (one queue per timeline)
48-
private readonly ConcurrentDictionary<Guid, ConcurrentQueue<TimelineRecord>> _timelineUpdateQueue = new ConcurrentDictionary<Guid, ConcurrentQueue<TimelineRecord>>();
48+
private readonly ConcurrentDictionary<Guid, ConcurrentQueue<TimelineRecord>> _timelineUpdateQueue = new();
4949

5050
// indicate how many timelines we have, we will process _timelineUpdateQueue base on the order of timeline in this list
51-
private readonly List<Guid> _allTimelines = new List<Guid>();
51+
private readonly List<Guid> _allTimelines = new();
5252

5353
// bufferd timeline records that fail to update
54-
private readonly Dictionary<Guid, List<TimelineRecord>> _bufferedRetryRecords = new Dictionary<Guid, List<TimelineRecord>>();
54+
private readonly Dictionary<Guid, List<TimelineRecord>> _bufferedRetryRecords = new();
5555

5656
// Task for each queue's dequeue process
5757
private Task _webConsoleLineDequeueTask;
@@ -61,8 +61,8 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
6161
// common
6262
private IJobServer _jobServer;
6363
private Task[] _allDequeueTasks;
64-
private readonly TaskCompletionSource<int> _jobCompletionSource = new TaskCompletionSource<int>();
65-
private readonly TaskCompletionSource<int> _jobRecordUpdated = new TaskCompletionSource<int>();
64+
private readonly TaskCompletionSource<int> _jobCompletionSource = new();
65+
private readonly TaskCompletionSource<int> _jobRecordUpdated = new();
6666
private bool _queueInProcess = false;
6767

6868
public TaskCompletionSource<int> JobRecordUpdated => _jobRecordUpdated;
@@ -237,8 +237,8 @@ private async Task ProcessWebConsoleLinesQueueAsync(bool runOnce = false)
237237
}
238238

239239
// Group consolelines by timeline record of each step
240-
Dictionary<Guid, List<TimelineRecordLogLine>> stepsConsoleLines = new Dictionary<Guid, List<TimelineRecordLogLine>>();
241-
List<Guid> stepRecordIds = new List<Guid>(); // We need to keep lines in order
240+
Dictionary<Guid, List<TimelineRecordLogLine>> stepsConsoleLines = new();
241+
List<Guid> stepRecordIds = new(); // We need to keep lines in order
242242
int linesCounter = 0;
243243
ConsoleLineInfo lineInfo;
244244
while (_webConsoleLineQueue.TryDequeue(out lineInfo))
@@ -264,7 +264,7 @@ private async Task ProcessWebConsoleLinesQueueAsync(bool runOnce = false)
264264
{
265265
// Split consolelines into batch, each batch will container at most 100 lines.
266266
int batchCounter = 0;
267-
List<List<TimelineRecordLogLine>> batchedLines = new List<List<TimelineRecordLogLine>>();
267+
List<List<TimelineRecordLogLine>> batchedLines = new();
268268
foreach (var line in stepsConsoleLines[stepRecordId])
269269
{
270270
var currentBatch = batchedLines.ElementAtOrDefault(batchCounter);
@@ -338,7 +338,7 @@ private async Task ProcessFilesUploadQueueAsync(bool runOnce = false)
338338
{
339339
while (!_jobCompletionSource.Task.IsCompleted || runOnce)
340340
{
341-
List<UploadFileInfo> filesToUpload = new List<UploadFileInfo>();
341+
List<UploadFileInfo> filesToUpload = new();
342342
UploadFileInfo dequeueFile;
343343
while (_fileUploadQueue.TryDequeue(out dequeueFile))
344344
{
@@ -398,13 +398,13 @@ private async Task ProcessTimelinesUpdateQueueAsync(bool runOnce = false)
398398
{
399399
while (!_jobCompletionSource.Task.IsCompleted || runOnce)
400400
{
401-
List<PendingTimelineRecord> pendingUpdates = new List<PendingTimelineRecord>();
401+
List<PendingTimelineRecord> pendingUpdates = new();
402402
foreach (var timeline in _allTimelines)
403403
{
404404
ConcurrentQueue<TimelineRecord> recordQueue;
405405
if (_timelineUpdateQueue.TryGetValue(timeline, out recordQueue))
406406
{
407-
List<TimelineRecord> records = new List<TimelineRecord>();
407+
List<TimelineRecord> records = new();
408408
TimelineRecord record;
409409
while (recordQueue.TryDequeue(out record))
410410
{
@@ -426,7 +426,7 @@ private async Task ProcessTimelinesUpdateQueueAsync(bool runOnce = false)
426426
// we need track whether we have new sub-timeline been created on the last run.
427427
// if so, we need continue update timeline record even we on the last run.
428428
bool pendingSubtimelineUpdate = false;
429-
List<Exception> mainTimelineRecordsUpdateErrors = new List<Exception>();
429+
List<Exception> mainTimelineRecordsUpdateErrors = new();
430430
if (pendingUpdates.Count > 0)
431431
{
432432
foreach (var update in pendingUpdates)
@@ -529,7 +529,7 @@ private List<TimelineRecord> MergeTimelineRecords(List<TimelineRecord> timelineR
529529
return timelineRecords;
530530
}
531531

532-
Dictionary<Guid, TimelineRecord> dict = new Dictionary<Guid, TimelineRecord>();
532+
Dictionary<Guid, TimelineRecord> dict = new();
533533
foreach (TimelineRecord rec in timelineRecords)
534534
{
535535
if (rec == null)

src/Runner.Common/ProcessChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public async Task SendAsync(MessageType messageType, string body, CancellationTo
7676

7777
public async Task<WorkerMessage> ReceiveAsync(CancellationToken cancellationToken)
7878
{
79-
WorkerMessage result = new WorkerMessage(MessageType.NotInitialized, string.Empty);
79+
WorkerMessage result = new(MessageType.NotInitialized, string.Empty);
8080
result.MessageType = (MessageType)await _readStream.ReadInt32Async(cancellationToken);
8181
result.Body = await _readStream.ReadStringAsync(cancellationToken);
8282
Trace.Info($"Receiving message of length {result.Body.Length}, with hash '{IOUtil.GetSha256Hash(result.Body)}'");

src/Runner.Common/ProcessExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public static class LinuxProcessExtensions
291291
public static string GetEnvironmentVariable(this Process process, IHostContext hostContext, string variable)
292292
{
293293
var trace = hostContext.GetTrace(nameof(LinuxProcessExtensions));
294-
Dictionary<string, string> env = new Dictionary<string, string>();
294+
Dictionary<string, string> env = new();
295295

296296
if (Directory.Exists("/proc"))
297297
{
@@ -322,8 +322,8 @@ public static string GetEnvironmentVariable(this Process process, IHostContext h
322322
// It doesn't escape '=' or ' ', so we can't parse the output into a dictionary of all envs.
323323
// So we only look for the env you request, in the format of variable=value. (it won't work if you variable contains = or space)
324324
trace.Info($"Read env from output of `ps e -p {process.Id} -o command`");
325-
List<string> psOut = new List<string>();
326-
object outputLock = new object();
325+
List<string> psOut = new();
326+
object outputLock = new();
327327
using (var p = hostContext.CreateService<IProcessInvoker>())
328328
{
329329
p.OutputDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stdout)

src/Runner.Common/Terminal.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public string ReadSecret()
8181
}
8282

8383
// Trace whether a value was entered.
84-
string val = new String(chars.ToArray());
84+
string val = new(chars.ToArray());
8585
if (!string.IsNullOrEmpty(val))
8686
{
8787
HostContext.SecretMasker.AddValue(val);

src/Runner.Common/TraceManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface ITraceManager : IDisposable
1414

1515
public sealed class TraceManager : ITraceManager
1616
{
17-
private readonly ConcurrentDictionary<string, Tracing> _sources = new ConcurrentDictionary<string, Tracing>(StringComparer.OrdinalIgnoreCase);
17+
private readonly ConcurrentDictionary<string, Tracing> _sources = new(StringComparer.OrdinalIgnoreCase);
1818
private readonly HostTraceListener _hostTraceListener;
1919
private TraceSetting _traceSetting;
2020
private ISecretMasker _secretMasker;

src/Runner.Listener/Checks/CheckUtil.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ await processInvoker.ExecuteAsync(
347347
public sealed class HttpEventSourceListener : EventListener
348348
{
349349
private readonly List<string> _logs;
350-
private readonly object _lock = new object();
351-
private readonly Dictionary<string, HashSet<string>> _ignoredEvent = new Dictionary<string, HashSet<string>>
350+
private readonly object _lock = new();
351+
private readonly Dictionary<string, HashSet<string>> _ignoredEvent = new()
352352
{
353353
{
354354
"Microsoft-System-Net-Http",

src/Runner.Listener/Checks/NodeJsCheck.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private async Task<CheckResult> CheckNodeJs(string url, string pat, bool extraCA
8686
result.Logs.Add($"{DateTime.UtcNow.ToString("O")} ***************************************************************************************************************");
8787

8888
// Request to github.com or ghes server
89-
Uri requestUrl = new Uri(url);
89+
Uri requestUrl = new(url);
9090
var env = new Dictionary<string, string>()
9191
{
9292
{ "HOSTNAME", requestUrl.Host },

src/Runner.Listener/CommandSettings.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace GitHub.Runner.Listener
1111
{
1212
public sealed class CommandSettings
1313
{
14-
private readonly Dictionary<string, string> _envArgs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
14+
private readonly Dictionary<string, string> _envArgs = new(StringComparer.OrdinalIgnoreCase);
1515
private readonly CommandLineParser _parser;
1616
private readonly IPromptManager _promptManager;
1717
private readonly Tracing _trace;
@@ -26,7 +26,7 @@ public sealed class CommandSettings
2626
};
2727

2828
// Valid flags and args for specific command - key: command, value: array of valid flags and args
29-
private readonly Dictionary<string, string[]> validOptions = new Dictionary<string, string[]>
29+
private readonly Dictionary<string, string[]> validOptions = new()
3030
{
3131
// Valid configure flags and args
3232
[Constants.Runner.CommandLine.Commands.Configure] =
@@ -137,7 +137,7 @@ public CommandSettings(IHostContext context, string[] args)
137137
// Validate commandline parser result
138138
public List<string> Validate()
139139
{
140-
List<string> unknowns = new List<string>();
140+
List<string> unknowns = new();
141141

142142
// detect unknown commands
143143
unknowns.AddRange(_parser.Commands.Where(x => !validOptions.Keys.Contains(x, StringComparer.OrdinalIgnoreCase)));

src/Runner.Listener/Configuration/ConfigurationManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task ConfigureAsync(CommandSettings command)
8686
throw new InvalidOperationException("Cannot configure the runner because it is already configured. To reconfigure the runner, run 'config.cmd remove' or './config.sh remove' first.");
8787
}
8888

89-
RunnerSettings runnerSettings = new RunnerSettings();
89+
RunnerSettings runnerSettings = new();
9090

9191
// Loop getting url and creds until you can connect
9292
ICredentialProvider credProvider = null;
@@ -521,7 +521,7 @@ private TaskAgent UpdateExistingAgent(TaskAgent agent, RSAParameters publicKey,
521521

522522
private TaskAgent CreateNewAgent(string agentName, RSAParameters publicKey, ISet<string> userLabels, bool ephemeral, bool disableUpdate)
523523
{
524-
TaskAgent agent = new TaskAgent(agentName)
524+
TaskAgent agent = new(agentName)
525525
{
526526
Authorization = new TaskAgentAuthorization
527527
{

src/Runner.Listener/Configuration/CredentialManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface ICredentialManager : IRunnerService
1818

1919
public class CredentialManager : RunnerService, ICredentialManager
2020
{
21-
public static readonly Dictionary<string, Type> CredentialTypes = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
21+
public static readonly Dictionary<string, Type> CredentialTypes = new(StringComparer.OrdinalIgnoreCase)
2222
{
2323
{ Constants.Configuration.OAuth, typeof(OAuthCredential)},
2424
{ Constants.Configuration.OAuthAccessToken, typeof(OAuthAccessTokenCredential)},

src/Runner.Listener/Configuration/CredentialProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override VssCredentials GetVssCredentials(IHostContext context)
4848
ArgUtil.NotNullOrEmpty(token, nameof(token));
4949

5050
trace.Info("token retrieved: {0} chars", token.Length);
51-
VssCredentials creds = new VssCredentials(new VssOAuthAccessTokenCredential(token), CredentialPromptType.DoNotPrompt);
51+
VssCredentials creds = new(new VssOAuthAccessTokenCredential(token), CredentialPromptType.DoNotPrompt);
5252
trace.Info("cred created");
5353

5454
return creds;

src/Runner.Listener/Configuration/ServiceControlManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void CalculateServiceName(RunnerSettings settings, string serviceNamePatt
4444
}
4545

4646
// For the service name, replace any characters outside of the alpha-numeric set and ".", "_", "-" with "-"
47-
Regex regex = new Regex(@"[^0-9a-zA-Z._\-]");
47+
Regex regex = new(@"[^0-9a-zA-Z._\-]");
4848
string repoOrOrgName = regex.Replace(settings.RepoOrOrgName, "-");
4949

5050
serviceName = StringUtil.Format(serviceNamePattern, repoOrOrgName, settings.AgentName);

0 commit comments

Comments
 (0)