aelij / ConfigureAwaitChecker

ConfigureAwait Checker for ReSharper and Rider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclude WebApi and ASP.NET controllers from analysis

asizikov opened this issue · comments

The ConfigureAwait(false); can be harmful when used from ASP.NET application as it's forces the method to continue outside of RequestContext.

More details:
http://stackoverflow.com/questions/13489065/best-practice-to-call-configureawait-for-all-server-side-code

The point of this extension is to be explicit about ConfigureAwait, be it true or false.

You can use ReSharper attributes to disable the warning for an entire class:

[SuppressMessage("ReSharper", "ConsiderUsingConfigureAwait")]

Ok, I see the point. The problem is that developers are used to hit 'alt+enter' and select the first suggestion. Do you think it makes sense to have default value placed on top of context menu based on project type/class type?

I think the false case is much more common. Devs should be more mindful when applying fixes. :)

I agree, they should, but I see this mistake popping up during code reviews from time to time.

My point was: the general rule for R# suggestions is not to hurt with defaults.

Let's say I change the order, won't that just introduce the reverse mistakes (true instead of false)?

I'll consider adding settings that allow you to define types where the inspection is turned off (e.g. Controller).

BTW, SynchronizationContext is gone in ASP.NET 5, so this won't be an issue in the future.

Yeah, that might do the trick. Thanks.

It would still be nice to have an assembly/project level ignore and/or default for this rule. Having it per class is too verbose.

I really like the idea of this extension, but it has far too much "green" for many projects where I simply do not care. I just want to disable the rule for the project rather than entirely.

@onovotny Yeah, I understand. I just don't have the time to invest in this right now.
BTW, you can change the default in ReSharper's solution settings so it's just a hint.

Another option is to use the Roslyn analyzer pack Microsoft.ApiDesignGuidelines.Analyzers. It contains the diagnostic (and code fix) CA2007: Do not directly await a Task. It works much the same way, and has the advantages of being project-specific and of showing up in automated builds (if it's configured as a warning or an error).