Skip to content

A command line tool for ensuring ConfigureAwait is specified for all awaits. Ideal for running in a CI pipeline.

License

Notifications You must be signed in to change notification settings

sliced-bread/Slicedbread.ConfigureAwaitEnforcer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Slicedbread.ConfigureAwaitEnforcer

A command line tool for ensuring ConfigureAwait() is specified for all await calls in a solution. Ideal for running in a CI pipeline.

  • Run on existing codebases - existing awaits without ConfigureAwait() will get a free pass on the first run of the tool. Only new/modified code on subsequent runs will flag an error, allowing you to add this to your pipeline now and fix existing code later
  • Supports dynamic - Enforces that when await is called on something dynamic, ConfigureAwait() must still be present
  • Quickly fix invalid awaits - Prints the project name, file name, line number and code for each invalid await
  • Integrates with CI pipelines - Uses a non-zero exit code when new invalid await is found, allowing you to fail the build
> Slicedbread.ConfigureAwaitEnforcer.exe   MySolution.sln
Parsing command line args
Loading solution MySolution.sln

Analysing:
  MyProject - 91 documents
  AnotherProject - 53 documents

Found 3 new await call(s) without ConfigureAwait
  
  MyProject - SomeFile.cs
    54: await DoSomethingAsync();
    70: var a = DoSomethingElseAsync();
  
  MyProject - AnotherFile.cs
    12: await DoSomethingAsync();

Parameters

Strict Mode

> Slicedbread.ConfigureAwaitEnforcer.exe  MySolution.sln  -strict

All await calls without ConfigureAwait() will cause a failure and be written to the console, regardless of whether they were present in the codebase on the first run.

Useful if you wish to find all existing invalid awaits in your codebase locally.

Ignoring Files

> Slicedbread.ConfigureAwaitEnforcer.exe  MySolution.sln  /excludeFiles "tests"  /excludeFiles "fixture" 

Ignores any file with a name containing the string passed to /excludeFiles.

You can specify this multiple times.

How does it work?

This tool uses The .NET Compiler Platform (a.k.a. Roslyn).

Most of the repository is boilerplate for writing to the console etc. The interesting code, for parsing a document to find awaits without ConfigureAwait(), is in DocumentAnalyser.cs

The tests for this code (useful for checking what syntax the tool does/does not support) are here

About

A command line tool for ensuring ConfigureAwait is specified for all awaits. Ideal for running in a CI pipeline.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages