Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adds CA2007 warning #170

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ dotnet_naming_symbols.public_members.applicable_kinds = property, field, method
dotnet_naming_symbols.public_members.applicable_accessibilities = public
dotnet_naming_symbols.public_members.required_modifiers =

dotnet_naming_style.public_uppercase_style.capitalization = pascal_case
dotnet_naming_style.public_uppercase_style.capitalization = pascal_case

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = warning
18 changes: 9 additions & 9 deletions src/OrasProject.Oras/Packer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public static async Task<Descriptor> PackManifestAsync(
switch (version)
{
case ManifestVersion.Version1_0:
return await PackManifestV1_0Async(pusher, artifactType, options, cancellationToken);
return await PackManifestV1_0Async(pusher, artifactType, options, cancellationToken).ConfigureAwait(false);
case ManifestVersion.Version1_1:
return await PackManifestV1_1Async(pusher, artifactType, options, cancellationToken);
return await PackManifestV1_1Async(pusher, artifactType, options, cancellationToken).ConfigureAwait(false);
default:
throw new NotSupportedException($"ManifestVersion({version}) is not supported");
}
Expand Down Expand Up @@ -146,7 +146,7 @@ private static async Task<Descriptor> PackManifestV1_0Async(IPushable pusher, st
artifactType = MediaTypeUnknownConfig;
}
ValidateMediaType(artifactType);
configDescriptor = await PushCustomEmptyConfigAsync(pusher, artifactType, options.ConfigAnnotations, cancellationToken);
configDescriptor = await PushCustomEmptyConfigAsync(pusher, artifactType, options.ConfigAnnotations, cancellationToken).ConfigureAwait(false);
}

var annotations = EnsureAnnotationCreated(options.ManifestAnnotations, "org.opencontainers.image.created");
Expand All @@ -159,7 +159,7 @@ private static async Task<Descriptor> PackManifestV1_0Async(IPushable pusher, st
Annotations = annotations
};

return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.Config.MediaType, manifest.Annotations, cancellationToken);
return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.Config.MediaType, manifest.Annotations, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -192,7 +192,7 @@ private static async Task<Descriptor> PackManifestV1_1Async(IPushable pusher, st
configDescriptor = Descriptor.Empty;
options.Config = configDescriptor;
var configBytes = new byte[] { 0x7B, 0x7D };
await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken);
await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken).ConfigureAwait(false);
}

if (options.Layers == null || options.Layers.Count == 0)
Expand All @@ -215,7 +215,7 @@ private static async Task<Descriptor> PackManifestV1_1Async(IPushable pusher, st
Annotations = annotations
};

return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.ArtifactType, manifest.Annotations, cancellationToken);
return await PushManifestAsync(pusher, manifest, manifest.MediaType, manifest.ArtifactType, manifest.Annotations, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -235,7 +235,7 @@ private static async Task<Descriptor> PushManifestAsync(IPushable pusher, object
manifestDesc.ArtifactType = artifactType;
manifestDesc.Annotations = annotations;

await pusher.PushAsync(manifestDesc, new MemoryStream(manifestJson), cancellationToken);
await pusher.PushAsync(manifestDesc, new MemoryStream(manifestJson), cancellationToken).ConfigureAwait(false);
return manifestDesc;
}

Expand Down Expand Up @@ -266,7 +266,7 @@ private static async Task<Descriptor> PushCustomEmptyConfigAsync(IPushable pushe
var configDescriptor = Descriptor.Create(configBytes, mediaType);
configDescriptor.Annotations = annotations;

await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken);
await PushIfNotExistAsync(pusher, configDescriptor, configBytes, cancellationToken).ConfigureAwait(false);
return configDescriptor;
}

Expand All @@ -280,7 +280,7 @@ private static async Task<Descriptor> PushCustomEmptyConfigAsync(IPushable pushe
/// <returns></returns>
private static async Task PushIfNotExistAsync(IPushable pusher, Descriptor descriptor, byte[] data, CancellationToken cancellationToken = default)
{
await pusher.PushAsync(descriptor, new MemoryStream(data), cancellationToken);
await pusher.PushAsync(descriptor, new MemoryStream(data), cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/OrasProject.Oras/Registry/Remote/BlobStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class BlobStore(Repository repository) : IBlobStore, IMounter
{
public Repository Repository { get; init; } = repository;

Check warning on line 30 in src/OrasProject.Oras/Registry/Remote/BlobStore.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Parameter 'Repository repository' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 30 in src/OrasProject.Oras/Registry/Remote/BlobStore.cs

View workflow job for this annotation

GitHub Actions / Analyze (8.0.x)

Parameter 'Repository repository' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 30 in src/OrasProject.Oras/Registry/Remote/BlobStore.cs

View workflow job for this annotation

GitHub Actions / Analyze (8.0.x)

Parameter 'Repository repository' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

public async Task<Stream> FetchAsync(Descriptor target, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -148,7 +148,7 @@
url = location.IsAbsoluteUri ? location : new Uri(url, location);
}

await CompletePushAsync(url, expected, content, cancellationToken);
await CompletePushAsync(url, expected, content, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -255,7 +255,8 @@
return stream;
}

await using (var contents = await GetContentStream())
var contents = await GetContentStream().ConfigureAwait(false);
await using (contents.ConfigureAwait(false))
{
await CompletePushAsync(url, descriptor, contents, cancellationToken).ConfigureAwait(false);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/OrasProject.Oras.Tests/OrasProject.Oras.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<!-- Disable requiring ConfigureAwait(false) for awaited tasks -->
<NoWarn>CA2007</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading