Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzers should not just tell you you're doing it wrong but what to do instead #1423

Closed
NinoFloris opened this issue Aug 22, 2017 · 12 comments

Comments

@NinoFloris
Copy link

NinoFloris commented Aug 22, 2017

xUnit2013/xUnit2015/xUnit2017/etc are nice but the warnings themselves are not talking about solutions.only about 'wrongdoings'.

Edit:
As not every dev uses an ide and the dotnet cli now runs these analyzers on build they could be a bit more descriptive

@jamesqo
Copy link
Contributor

jamesqo commented Aug 23, 2017

@NinoFloris Thanks for your feedback! I understand that you feel like we're telling the user what they shouldn't do, and not enough of what they should do.

I didn't write most of the rules you mention, but I believe the reason behind that is we offer code fixes that will show you how to correct your code. For xUnit2017, for example, if you press Ctrl+. in Visual Studio around the site of the warning, it should offer to convert Assert.True(c.Contains(...)) to Assert.Contains(..., c), or Assert.False(c.Contains(...)) to Assert.DoesNotContain(..., c).

/cc @marcind

@NinoFloris
Copy link
Author

NinoFloris commented Aug 23, 2017 via email

@jamesqo
Copy link
Contributor

jamesqo commented Aug 23, 2017

@NinoFloris Are you saying you got warning in VSCode, but not a codefix? That's strange, since from this issue it looks like VSCode supports neither analyzers nor codefixes yet: dotnet/vscode-csharp#43. Also, Project Rider doesn't use Roslyn.

@NinoFloris
Copy link
Author

NinoFloris commented Aug 23, 2017 via email

@jamesqo
Copy link
Contributor

jamesqo commented Aug 23, 2017

@NinoFloris I see. I guess it couldn't hurt to be a little more detailed in the message, then. I'm not an official maintainer, but @marcind if you concur you can mark this up for grabs.

@vcsjones
Copy link

vcsjones commented Oct 9, 2017

Agree. The quick fixes aren't enough to document what the expectation is, especially for non-Visual Studio users. This has resulted in at least one Stack Overflow question.

@julielerman
Copy link

This has me going in circles today..."don't use equal to verify collection size" but no hints and I can't figure out another way.

@bradwilson
Copy link
Member

bradwilson commented May 14, 2018

The documentation still has holes, but each analyzer should link to the documentation page for the rule, which should include examples of both "wrong" and "right" code. For example: https://xunit.github.io/xunit.analyzers/rules/xUnit2013

These links are included in the "metadata" passed back to the analyzer engine when rules are flagged. Are these links not made visible when the .NET CLI flags the rules?

@julielerman
Copy link

I finally woke up to the fact that I was comparing it to 1 and changed it to single. In the meantime, I'm using VS Code and this is what I got on dotnet build before I made the change:

Build succeeded.

UnitTest1.cs(43,13): warning xUnit2013: Do not use Assert.Equal() to check for collection size. [/Users/julielerman/blahblahblah/Demos/v1/test/test.csproj]
    1 Warning(s)
    0 Error(s)

@marcind
Copy link
Member

marcind commented May 14, 2018

Looks like the descriptor messageFormats could be augmented with a short bit on what should be done instead.

@bradwilson
Copy link
Member

Yeah, that's a bummer that they don't include the help link. 😞

@ThorstenHans
Copy link

Thanks to @bradwilson for posting the link here. Luckily Assert.Single(collection); works for my test scenario too, but I'd love to see something like:

Assert.CountEquals(10, collection)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants