Microsoft Source Analysis
First question: do you use FxCop? Do I…not really. But I try not to tell too many people that either.
So there is a new tool out there for all of you who need help keeping your source code up to snuff, similar to what FxCop does for your API…just at the source code level. It is called the Microsoft Source Analysis for C# (sorry VB). BTW, there is also a blog.
I happen to have a project that I am in the midst of doing some spring cleaning anyway, so I decided to try it out. You right click on the project or class you want to check, and select “Run Source Analysis”. Then in a tool window you will see a list of your failings as a developer.
Right off the bad I had a few issues with the list of failures. Every code file has to have a header.
Here is my “new” standard header to make it happy:
Lucky for me ReSharper can make that easy to add, but the ReSharper standard “File Header Text” in the ReSharper options does not allow you to have macros, or that would have been a lot easier.
Also, the Source Analysis does not like underscores on field names. So this will get a red ‘x’
and that is just not right. In fact, I want just the opposite. (Note: although, this will make one cranky old dutchman that I know very happy — he doesn’t like underscores).
But lucky for me, it is easy to turn things off, which I do. Right-click on your project file and select “Source Analysis Settings” and you can change anything you want. The bad news, it is on a project by project basis. The good news is that the files are merge-able. This also means there is a new file that gets added to your project, mine is: Settings.SourceAnalysis. Be sure to add that to your source control. 🙂
The other thing I like about it: it detects Hungarian notation (a prior sin that I am currently making penance for). “SA1305: The variable name ‘oElement’ begins with a prefix that looks like Hungarian notation.” But, if you like that sort of thing, back in the options is a way to tell the tools which Hungarian prefixes are acceptable.
But this could get ugly
OK, there are a few other concerns looming here. I’m calling it Dueling Source Officers. One tool will say two spaces between methods, the next will say one space. One tool like spaces, the other likes tabs. (for the record, Source Analysis HATES tabs, and thinks multiple lines between methods is plane evil). The other officer: ReSharper Code Analysis and ReSharper Code Reformat. Lucky for us ReSharper’s tools are very configurable…but it could take a while to get the two in sync.
Not throw in FxCop (now integrated into the Team Systems version of Visual Studio) and it can get very interesting.
The next steps are simple:
1. Learn how to write your own rules (I want my underscores)
2. Figure out how to integrate into Team City and Cruise Control (Code Analysis ships with an MSBuild task), and get something meaning full out of it.