Source Analysis (aka StyleCop)

Like many people I’ve been waiting for this one for a long time. Last week Microsoft released Source Analysis (aka StyleCop). Source Analysis is a free utility for analysing C# source code (Source Analysis does for source code what FxCop does for assemblies). It ensures consistency of code style throughout a project (and across all developers on a team). Source Analysis has approximately 200 rules covering all those niggley bits like whether to include spaces, whether to use spaces or tabs, where curly braces should be used, how comments should be used etc. etc. Imagine anything you have ever argued about with other developers on your team with regard to ’good style’ and Source Analysis has a rule for it. Of course, like FxCop the first time you use it Source Analysis will throw up hundreds of errors but also like FxCop you can disable any of the rules and if you don’t have time to fix them all you can disable the whole lot and then enable them progressively as you can spare 10 minutes here and there. You can even write your own StyleCop rules but this isn’t officially supported in this release.

You can download it from http://code.msdn.microsoft.com/sourceanalysis. You can read the Source Analysis blog at http://blogs.msdn.com/sourceanalysis. After installing Source Analysis you will notice that the current release is 4.2 which will seem odd given that this is the first public release. The explanation is that Microsoft have been using this tool internally across most teams that use C# for years. Consequently this is a very mature product that has had many of its rough edges knocked off already.

Another Source Analysis feature that I really like is that apart from the fact that it can be integrated into the Visual Studio IDE and the build process you can set Source Analysis to treat its warnings as errors - so for those who are particularly strict on coding standards you can set Source Analysis so that any code style deviation breaks the build.

It’s worth pointing out though it’s just for C# - no Visual Basic support here. Although it can be argued that to some extent Visual Basic doesn’t need Source Analysis because the editor ensures code style consistency without additional help and this is a feature that Visual Basic developers have enjoyed for years.

And in the next version of Source Analysis there will be the option to automatically fix errors.

Thanks for releasing this one, Microsoft, it will make a big difference - not to mention the initial flush of religious code style wars that we will be part of over the next year.

Technorati Tag: Source Analysis, StyleCop, FxCop

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Friday, May 30, 2008 at 9:54 PM
Categories: Miscellaneous - Technical
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments