aelij / ConfigureAwaitChecker

ConfigureAwait Checker for ReSharper and Rider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable analysis for test assemblies

espenalb opened this issue · comments

Hi - and thanks for an excellent plugin!

I see that you have a test asserting that the extension ignores test classes, but I did not figure out how it works.

Do your require that test classes start with test? Or is there some other mechanism at play here?

We are using another R# extension – TestCop – which aligns our test code with production code through namespaces and a simple RegEx.

Common.Utils.SomeClass defined in Common.dll has test code defined in Common.Tests.dll, namespace Common.Tests.Utils.SomeClassTests

This pattern is not recognized by your extension, and we therefore get a lot of “noise” in our test code where ConfigureAwait makes less sense…

Any chance you could fix this? Or anything I could do on my side to fix this?

Sorry for the late response.

There's no feature that ignores tests (I don't know where you saw the assert you spoke of). Filtering by class names is a feature that has been requested (see #4), so I may add it at one point. For now, you can use this attribute on your test classes to suppress the warnings:

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

OK. Works as expected. I think it would be very useful to implement #4 - there are typically namespaces where ConfigureAwait(false) will crash the application...

It should only ask to configure await in class libraries. Also, I have an extension method called AnyContext() which sets ConfigureAwait(false), would this plugin be smart enough to detect this?

Yes. The extension checks whether the awaited expression's type is a Task,
and if so, issues the warning. I'm assuming AnyContext() returns an
awaitable, which should be fine.

I'm willing to work on this.
Ideally it should entirely skip test projects, right? Looking for <OutputType>Library</OutputType> and <ProjectTypeGuids> not containing {3AC096D0-A1C2-E12C-1390-A8335801FDAB} (test) or any of the MVC project type guids?

It should skip entry points (gui projects, web projects and test projects)

Thanks
-Blake Niemyjski

On Fri, Nov 11, 2016 at 3:04 PM, Joseph Musser notifications@github.com
wrote:

I'm willing to work on this.
Ideally it should entirely skip test projects, right?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA-SoxHySGMgqfNQhDJHjQndtPy0wzvWks5q9NhQgaJpZM4GN2-M
.

Technically web and test projects don't have entry points represented in the .csproj or any other file, right? The tooling just works around the .csproj guids I'm pretty sure. The build output in both cases is a DLL with no entry point and then vstest or IIS Express is invoked on it?

I wouldn't attempt to apply this automatically to predetermined project types.

Instead I suggest an assembly-level attribute:

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

@aelij no one I can think of will ever want ConfigureAwait(false) enforcement in a WPF or Windows Forms or ASP.NET app, and it's unlikely for a console app too. Wouldn't it be better to ignore them by default and, if anything, allow opt-in using an assembly attribute?

@jnm2 I would rather it be opt-in and not automatic. Even in WPF programs, there are a lot of places where not going back to the dispatcher thread makes sense.

@aelij I think we just used 'opt-in' to mean opposite things, but I'm good with whatever you think makes sense. Just so I'm not confused, you think it's best to get warnings by default in test projects until you opt out of warnings, rather than not getting warnings by default in test projects unless you opt in to warnings?

@jnm2 Yes. As with all ReSharper suppression attributes, it would disable the warnings.

@aelij I wish there could be a way to use a new attribute that ConfigureAwaitChecker would recognize that would allow opting in (for test assemblies) as well opting out (for class libraries). Without that, this extension will be less useful to me. I work on so many projects where I can't just put warning suppression for my extensions in other people's code. I'll just have to get used to ignoring the underline.