Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 2a6a0d9

Browse files
authored
Raise AnalysisLevel to 6.0-Recommended, fix warnings (#2086)
Raise the .NET Code Analysis Level to `6.0-Minimum` and then `6.0-Recommended`.
1 parent 3c3aeaa commit 2a6a0d9

24 files changed

+100
-64
lines changed

src/ApiService/.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,26 @@ csharp_preserve_single_line_blocks = true
139139

140140
[*.{cs}]
141141
dotnet_diagnostic.IDE0005.severity = warning
142+
143+
# allow use of FirstOrDefault/LastOrDefault: https://github.com/dotnet/roslyn-analyzers/issues/1817 & https://github.com/dotnet/roslyn-analyzers/pull/4211#issuecomment-1003578755
144+
dotnet_code_quality.CA1826.exclude_ordefault_methods = true
145+
146+
# permit underscores in identifier names (e.g. tests, constants)
147+
dotnet_diagnostic.CA1707.severity = none
148+
149+
# don't care about names that conflict with keywords in other languages
150+
dotnet_diagnostic.CA1716.severity = none
151+
152+
# don't care about names that contain built-in identifiers
153+
dotnet_diagnostic.CA1711.severity = none
154+
dotnet_diagnostic.CA1720.severity = none
155+
156+
# allow static fields on generic types
157+
dotnet_diagnostic.CA1000.severity = none
158+
159+
# don't worry about performance of ILogger invocations (yet?)
160+
dotnet_diagnostic.CA1848.severity = none
161+
162+
# allow throwing base "Exception" class, since it's done a lot
163+
# TODO: improve this
164+
dotnet_diagnostic.CA2201.severity = suggestion

src/ApiService/ApiService/Log.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ public void Flush() {
5959
//TODO: Should we write errors and Exception to std err ?
6060
class Console : ILog {
6161

62-
private string DictToString<T>(IReadOnlyDictionary<string, T>? d) {
62+
private static string DictToString<T>(IReadOnlyDictionary<string, T>? d) {
6363
if (d is null) {
6464
return string.Empty;
6565
} else {
6666
return string.Join("", d);
6767
}
6868
}
6969

70-
private void LogTags(Guid correlationId, IReadOnlyDictionary<string, string> tags) {
70+
private static void LogTags(Guid correlationId, IReadOnlyDictionary<string, string> tags) {
7171
var ts = DictToString(tags);
7272
if (!string.IsNullOrEmpty(ts)) {
7373
System.Console.WriteLine($"[{correlationId}] Tags:{ts}");
7474
}
7575
}
7676

77-
private void LogMetrics(Guid correlationId, IReadOnlyDictionary<string, double>? metrics) {
77+
private static void LogMetrics(Guid correlationId, IReadOnlyDictionary<string, double>? metrics) {
7878
var ms = DictToString(metrics);
7979
if (!string.IsNullOrEmpty(ms)) {
8080
System.Console.Out.WriteLine($"[{correlationId}] Metrics:{DictToString(metrics)}");
@@ -126,7 +126,7 @@ internal interface ILogTracerInternal : ILogTracer {
126126

127127

128128
public class LogTracer : ILogTracerInternal {
129-
private string? GetCaller() {
129+
private static string? GetCaller() {
130130
return new StackTrace()?.GetFrame(2)?.GetMethod()?.DeclaringType?.FullName;
131131
}
132132

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public enum ErrorCode {
88
INVALID_PERMISSION = 451,
99
MISSING_EULA_AGREEMENT = 452,
1010
INVALID_JOB = 453,
11-
INVALID_TASK = 453,
11+
INVALID_TASK = INVALID_JOB,
1212
UNABLE_TO_ADD_TASK_TO_JOB = 454,
1313
INVALID_CONTAINER = 455,
1414
UNABLE_TO_RESIZE = 456,

src/ApiService/ApiService/OneFuzzTypes/Model.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public InstanceConfig(string instanceName) : this(
333333
"Standard_B2s") { }
334334
public InstanceConfig() : this(String.Empty) { }
335335

336-
public List<Guid>? CheckAdmins(List<Guid>? value) {
336+
public static List<Guid>? CheckAdmins(List<Guid>? value) {
337337
if (value is not null && value.Count == 0) {
338338
throw new ArgumentException("admins must be null or contain at least one UUID");
339339
} else {

src/ApiService/ApiService/QueueTaskHeartbeat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public QueueTaskHearbeat(ILoggerFactory loggerFactory, ITaskOperations tasks, IE
2020

2121
[Function("QueueTaskHeartbeat")]
2222
public async Async.Task Run([QueueTrigger("task-heartbeat", Connection = "AzureWebJobsStorage")] string msg) {
23-
_logger.LogInformation($"heartbeat: {msg}");
23+
_logger.LogInformation("heartbeat: {Message}", msg);
2424

2525
var hb = JsonSerializer.Deserialize<TaskHeartbeatEntry>(msg, EntityConverter.GetJsonSerializerOptions()).EnsureNotNull($"wrong data {msg}");
2626

2727
var task = await _tasks.GetByTaskId(hb.TaskId);
2828

2929
if (task == null) {
30-
_logger.LogWarning($"invalid task id: {hb.TaskId}");
30+
_logger.LogWarning("invalid task id: {TaskId}", hb.TaskId);
3131
return;
3232
}
3333

src/ApiService/ApiService/TimerDaily.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public TimerDaily(ILoggerFactory loggerFactory, IScalesetOperations scalesets, I
2121
public async Async.Task Run([TimerTrigger("1.00:00:00")] TimerInfo myTimer) {
2222
var scalesets = _scalesets.Search();
2323
await foreach (var scaleset in scalesets) {
24-
_logger.LogInformation($"updating scaleset configs: {scaleset.ScalesetId}");
24+
_logger.LogInformation("updating scaleset configs: {ScaleSetId}", scaleset.ScalesetId);
2525
// todo: do it in batches
2626
await _scalesets.Replace(scaleset with { NeedsConfigUpdate = true });
2727
}
2828

2929

3030
var expiredWebhookLogs = _webhookMessageLogs.SearchExpired();
3131
await foreach (var logEntry in expiredWebhookLogs) {
32-
_logger.LogInformation($"stopping expired webhook message log: {logEntry.WebhookId}:{logEntry.EventId}");
32+
_logger.LogInformation("stopping expired webhook message log: {WebhookId}:{EventId}", logEntry.WebhookId, logEntry.EventId);
3333
await _webhookMessageLogs.Delete(logEntry);
3434
}
3535
}

src/ApiService/ApiService/onefuzzlib/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Config(IContainers containers, IServiceConfig serviceConfig, IQueue queue
2121
_queue = queue;
2222
}
2323

24-
private BlobContainerSasPermissions ConvertPermissions(ContainerPermission permission) {
24+
private static BlobContainerSasPermissions ConvertPermissions(ContainerPermission permission) {
2525
BlobContainerSasPermissions blobPermissions = 0;
2626
if (permission.HasFlag(ContainerPermission.Read)) {
2727
blobPermissions |= BlobContainerSasPermissions.Read;

src/ApiService/ApiService/onefuzzlib/Containers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface IContainers {
1414
public Async.Task<BlobContainerClient?> FindContainer(Container container, StorageType storageType);
1515

1616
public Async.Task<Uri> GetFileSasUrl(Container container, string name, StorageType storageType, BlobSasPermissions permissions, TimeSpan? duration = null);
17-
public Async.Task SaveBlob(Container container, string v1, string v2, StorageType config);
17+
public Async.Task SaveBlob(Container container, string name, string data, StorageType storageType);
1818
public Async.Task<Guid> GetInstanceId();
1919

2020
public Async.Task<Uri?> GetFileUrl(Container container, string name, StorageType storageType);
@@ -125,7 +125,7 @@ public async Async.Task<Uri> GetFileSasUrl(Container container, string name, Sto
125125
return sasUrl;
126126
}
127127

128-
public (DateTimeOffset, DateTimeOffset) SasTimeWindow(TimeSpan timeSpan) {
128+
public static (DateTimeOffset, DateTimeOffset) SasTimeWindow(TimeSpan timeSpan) {
129129
// SAS URLs are valid 6 hours earlier, primarily to work around dev
130130
// workstations having out-of-sync time. Additionally, SAS URLs are stopped
131131
// 15 minutes later than requested based on "Be careful with SAS start time"
@@ -149,7 +149,7 @@ public async Async.Task SaveBlob(Container container, string name, string data,
149149
public Async.Task<Guid> GetInstanceId() => _getInstanceId.Value;
150150
private readonly Lazy<Async.Task<Guid>> _getInstanceId;
151151

152-
public Uri? GetContainerSasUrlService(
152+
public static Uri? GetContainerSasUrlService(
153153
BlobContainerClient client,
154154
BlobSasPermissions permissions,
155155
bool tag = false,

src/ApiService/ApiService/onefuzzlib/Defs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static class Defs {
44

5-
public static Dictionary<TaskType, TaskDefinition> TASK_DEFINITIONS = new Dictionary<TaskType, TaskDefinition>() {
5+
public static readonly IReadOnlyDictionary<TaskType, TaskDefinition> TASK_DEFINITIONS = new Dictionary<TaskType, TaskDefinition>() {
66
{ TaskType.Coverage ,
77
new TaskDefinition(
88
Features: new[] {

src/ApiService/ApiService/onefuzzlib/Events.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public Events(IQueue queue, IWebhookOperations webhook, ILogTracer log, IContain
3535
_creds = creds;
3636
}
3737

38-
public async Async.Task QueueSignalrEvent(EventMessage eventMessage) {
39-
var message = new SignalREvent("events", new List<EventMessage>() { eventMessage });
40-
await _queue.SendMessage("signalr-events", JsonSerializer.Serialize(message), StorageType.Config);
38+
public async Async.Task QueueSignalrEvent(EventMessage message) {
39+
var ev = new SignalREvent("events", new List<EventMessage>() { message });
40+
await _queue.SendMessage("signalr-events", JsonSerializer.Serialize(ev), StorageType.Config);
4141
}
4242

4343
public async Async.Task SendEvent(BaseEvent anEvent) {

0 commit comments

Comments
 (0)