Wintellect.Analyzers
At Wintellect, we love anything that will help us write the best code possible. Microsoft's new Roslyn compiler is a huge step in that direction so we had to jump in and start writing analyzers and code fixes we've wanted for years. Feel free to fork and add your own favorites. We'll keep adding these as we think of them.
To add these analyzers to your project easily, use the NuGet package. In the Visual Studio Package Manager Console exeute the following:
Install-Package Wintellect.Analyzers
Design Analyzers
AssembliesHaveCompanyAtrribute
This warning ensures you have the AssemblyCompanyAttribute present and a filled out value in the parameter.
AssembliesHaveCopyrightAtrribute
This warning ensures you have the AssemblyCopyrightAttribute present and a filled out value in the parameter.
AssembliesHaveDescriptionAtrribute
This warning ensures you have the AssemblyDescriptionAttribute present and a filled out value in the parameter.
AssembliesHaveTitleAtrribute
This warning ensures you have the AssemblyTitleAttribute present and a filled out value in the parameter.
CatchBlocksShouldRethrow
This informational analyzer will report when you have a catch block that eats an exception. Because exception handling is so hard to get right, this notification is important to remind you too look at those catch blocks.
Documentation Analyzers
ExceptionDocumentationMissing
If you have a direct throw in your code, you need to document it with an tag in the XML documentation comments. A direct throw is one where you specifically use the throw statement in your code. This analyzer does not apply to private methods, only accessibility levels where calls outside the defining method can take place.
SuppressionMessageMissingJustification
If you are using the SuppressionMessage attribute to suppress Code Analysis items, you need to fill out the Justification property to explicitly state why you are suppressing the report instead of fixing the code.
Formatting Analyzers
IfAndElseMustHaveBraces
If and else statements without braces are reasons for being fired. This analyzer and code fix will help you keep your job. :) The idea for this analyzer was shown by Kevin Pilch-Bisson in his awesome TechEd talk. We just finished it off.
Performance Analyzers
AvoidCallingMethodsWithParamArgsInLoops
This informational level check gives you a hint that you are calling a method using param arrays inside a loop. Because calls to these methods cause memory allocations you should know where these are happening.
Usage Analzyers
AvoidPredefinedTypes
The predefined types, such as int, should not be used. You want to be as explicit about types as possible to avoid confusion.
CallAssertMethodsWithMessageParameter
Calling the one parameter overload of Debug.Assert is a bad idea because they will not show you the expression you are asserting on. This analyzer will find those calls and the code fix will take the asserting expression and convert it into a string as the second parameter to the two parameter overload of Debug.Assert.
ClassesShouldBeSealed
When creating new classes, they should be declared with the the sealed modifier.
ReturningTaskRequiresAsync
If you are returning a Task or Task from a method, that method name must end in Async.
UseDebuggerDisplay
An analyzer and code fix for inserting DebuggerDisplayAttribute onto public classes. The debugger uses the DebuggerDisplayAttribute to display the class in the expression evaluator (watch/autos/locals windows, data tips) so you can see the important information quickly. The code fix will pull in the first two properties (or fields if one or no properties are present). If the class is derived from IEnumerable, it will default to the count of items.