Company Roslyn analyzers for enforcing Pandatech coding rules.
Currently the package contains rules around async method conventions, and is intended to grow over time with additional internal policies.
Definition of async:
A method is considered async if its return type is one of:
System.Threading.Tasks.TaskSystem.Threading.Tasks.Task<T>System.Threading.Tasks.ValueTaskSystem.Threading.Tasks.ValueTask<T>
Rule:
Such methods must have a name ending with Async.
Examples:
Task<int> GetValueAsync(CancellationToken ct); // OK
Task<int> GetValue(CancellationToken ct); // PT0001Async methods must include a CancellationToken parameter:
Examples:
Task<int> GetValueAsync(int id, CancellationToken ct); // OK
Task<int> GetValueAsync(); // PT0002If an async method declares a CancellationToken, it must be named ct.
Examples:
Task<int> GetValueAsync(int id, CancellationToken ct); // OK
Task<int> GetValueAsync(int id, CancellationToken token); // PT0003PT0004 – CancellationToken parameter must be last
If an async method declares a CancellationToken, it must be the last parameter.
Examples:
Task<int> GetValueAsync(int id, CancellationToken ct); // OK
Task<int> GetValueAsync(CancellationToken ct, int id); // PT0004
Task<int> GetValueAsync(CancellationToken ct); // OKAdd the package to the projects you want analyzed:
<ItemGroup>
<PackageReference Include="Pandatech.Analyzers" Version="1.0.0" PrivateAssets="all"/>
</ItemGroup>Configure severities via .editorconfig:
dotnet_diagnostic.PT0001.severity = error # Async suffix
dotnet_diagnostic.PT0002.severity = error # CT missing
dotnet_diagnostic.PT0003.severity = error # CT name
dotnet_diagnostic.PT0004.severity = error # CT position