Testing Custom Code Analysis Rules

By Michael Flanakin @ 3:55 AM :: 1934 Views :: .NET, Development, Microsoft, Predictions, Tools/Utilities :: Digg it!

Microsoft .NET

Over the years, I've been asked to put together coding standards again and again. The nice thing about this is that it enables me to pull out the old docs and touch them up a little. A year or two ago, I heard something that made a lot of sense: developers never really read coding standards and, even if they do, they don't usually adopt them. Let's face it, if you don't adopt a standard as your own, you're not going to use it. The only way to ensure the standard is applied is to catch the problem before it gets checked in. I tried a VS add-in that attempted to do this as you type, but it wasn't quite as extensive as I want, but I grabbed onto the concept. For the past year, I've been wanting to start this and have finally decided to do it.

As I sat down and started to investigate writing custom code analysis rules, I asked myself how I was going to validate them. After hacking away at one approach after another, I started to realize I wasn't going to get very far. Apparently, with the latest releases of Visual Studio and FxCop, there's no way to create the objects used to represent code. After talking to the product team, the official position seems to be that, since custom rules aren't "officially supported," they're not going to support their testability. I'm not sure who made this decision, but I think it's a bad one. Of course, I say this without knowing their plans. Well, not completely, anyway.

It's not all bad news, however. It turns out there are hopes to start officially supporting custom code analysis rules in the next major release, Visual Studio 10. Nothing's being promised at this point, it's just something the team would like to deliver. I should also say that the upcoming Rosario release isn't the major release I'm referring to. I'm expecting Rosario to be a 9.1 release that will probably hit the streets in early 2009. That's a guess, tho. If that's true, the VS 10 release probably wouldn't be until 2011. All I can really say about it is that it'll be a very exciting release. I can't wait to get my hands on a beta. Speaking of which, some of the goals they have for the product will make beta testing much much easier... I'm talking about a hugely evolutionary change, if not revolutionary, considering where the product is today. That's all I can really say, tho.

Back to the point, since there's no realy testability of the code analysis framework, I decided to create my own object model. The part I'm missing, obviously, is the factory logic that converts code analysis types to my types. I'm hesitant about this approach, but it's working so far. Hopefully, I'll have something to deliver soon. I keep bouncing around, tho, so at this point, I want to deliver a release with only naming conventions. That release is mostly complete, I just need to get approval for a distribution mechanism. If I don't get that soon, I'll just release it on my site.

Ratings