sdk/tools/Azure.SdkAnalyzers/docs/list-of-diagnostics.md
Public types (classes, interfaces, or structs) in Azure SDK namespaces use single-word names, which are too generic and have a high chance of collision with BCL types or types from other libraries.
Use descriptive multi-word names for public types. Add a prefix or suffix that describes the purpose or domain of the type.
The following code defines a public class with a single-word name Format, which causes a violation of AZC0012.
namespace Azure.Data.Tables
{
public class Format { } // This will cause AZC0012
}
Add a descriptive prefix to make the type name more specific and avoid collisions. Common patterns include adding the service name (e.g., TableFormat, BlobFormat) or functionality (e.g., TableDataFormat).
namespace Azure.Data.Tables
{
- public class Format { } // This will cause AZC0012
+ public class TableDataFormat { }
}
// ❌ Avoid single-word names
public class Manager { }
public interface IService { }
public struct Options { }
// ✅ Use descriptive multi-word names
public class TableManager { }
public interface ITableService { }
public struct TableClientOptions { }
Azure. except Azure.Core.*)IClient is considered single-word)A method that accepts a CancellationToken parameter calls an Azure SDK API with a RequestContext parameter, but does not propagate the cancellation token to the RequestContext.
Set the CancellationToken property on the RequestContext object to the incoming cancellation token.
The following code defines a method that accepts a CancellationToken but does not propagate it to the RequestContext when calling an Azure SDK API.
public async Task UpdateAsync(CancellationToken cancellationToken)
{
// ❌ CancellationToken is accepted but not propagated
await client.UpdateAsync(
content,
new RequestContext()); // cancellationToken is dropped
}
Set the CancellationToken property on the RequestContext to ensure proper cancellation support.
public async Task UpdateAsync(CancellationToken cancellationToken)
{
- await client.UpdateAsync(
- content,
- new RequestContext()); // cancellationToken is dropped
+ await client.UpdateAsync(
+ content,
+ new RequestContext
+ {
+ CancellationToken = cancellationToken
+ });
}
// ❌ Avoid dropping cancellation tokens
public async Task BadAsync(CancellationToken token)
{
await client.UpdateAsync(content, new RequestContext());
await client.DeleteAsync(id, new RequestContext { ErrorOptions = ErrorOptions.Default });
}
// ✅ Propagate cancellation tokens
public async Task GoodAsync(CancellationToken token)
{
await client.UpdateAsync(content, new RequestContext { CancellationToken = token });
await client.DeleteAsync(id, new RequestContext
{
CancellationToken = token,
ErrorOptions = ErrorOptions.Default
});
}
Azure namespace)RequestContext is passed from a parameter or local variableCancellationToken to CancellationToken.None or default when a cancellation token parameter is available will still trigger a warning