Update: StyleCop for ReSharper is now feature complete.
[UPDATE] See post "StyleCop for ReSharper on CodePlex" for more info.
I've worked on a couple of projects for Microsoft UK - one of the many great aspects of those projects was being able to use some very cool internal tools; my two favourites being the pre-cursors to Team Foundation Server (Product Studio + Source Depot) and StyleCop - which is to source code what FxCop is to binaries.
StyleCop quickly found a very special place in my heart - mainly because it soothed my coding standards / consistency / best practice OCD. I'm a fervent believer in coding standards - not only for the obvious reasons of consistency and maintainability - but mainly because I like the aesthetics of elegant code. It's hard to describe without sounding like a kook, but I find code formatting and refactoring quite soothing while I'm trying to solve bigger business logic problems - it helps me get into the zone. Consistently well formatted code sits well in my visuospatial sketchpad - it forms visual patterns that are easy to recognise when scanning code - an upshot of which is that it's very easy to see out of place (bad / sloppy) code and thus spot where bugs are likely to appear.
Using StyleCop meant an end to all the stupid arguments I used to get embroiled in whenever a new developer would start on a project; even though there was obviously a standard in place that the team was adhering to, the new developer would insist on coding "m_" styleee because that's how they'd always coded. StyleCop became the H-Bomb argument killer - if you didn't conform to the standard, you would break the build. With one less thing to worry about, your team can focus on the much more important issue of delivering business value to the customer.
The genius behind StyleCop is Jason Allor - he's done an awesome job by not only creating a tool which the whole C# community has been crying out for, but also achieved the amazing feat of getting buy-in from (or wrangling) a large number the internal MS teams to adopt StyleCop; hopefully this is a win-win situation as it helps make the products better, but also if Microsoft continues to push the envelope with it's transparency - we should all benefit.
After many people begged for it to be released externally, StyleCop has been rebranded as Microsoft Source Analysis for C# (MSAFC) and released on the MSDN Code Gallery, Jason has also created a Source Analysis blog where documentation, hints, tips and trivia will live. The first release has MSBuild integration and wonderfully Eugene Zakhareyev has already created a TFS Check-In Policy
One aspect that already amuses me is the number of people who are regurgitating many of the internal arguments that happened during StyleCop's infancy - "what do you mean 'use spaces instead of tabs'! No way - spaces are evil" - or the number of people who have raised issues because they want to be able to selectively turn rules on and off. Duh. I really hope Jason has copies of those flame-war threads so he can publish them onto the blog so that people understand the reasoning behind the rules - if only to highlight the point that if 1000's of Microsoft Product Team Developers can agree - then persuading your development team to adopt the rules should be easy.
When time came to leave those Microsoft UK internal projects - the hardest part was going through StyleCop withdrawal. When I went to the Team System SDR in 2004 I begged and pleaded like a fanatic to have StyleCop included in the product - but it was not to happen. I started to look around the web for alternative tools - but there were only pale imitations. So I started to do a little research into what it would take to write my own.
I soon discovered that I was no-where near hardcore enough to write my own C# parser - even worse, many of the open source ones only worked for .NET 1 / 1.1 and had not been updated to support 2.0 with generics support - and as Conchango deals with cutting edge .NET projects we need .NET 3.5 language features to be supported (although I have just discovered LINQ over C# - which looks like it could do the trick!). I started looking at DXCore but then on a tangent started to see if there was anyway to extend ReSharper via their Open API. There wasn't a huge amount of documentation - but I managed to piece together what was required from a few blog posts and samples. I wanted to create a tool that had the features of StyleCop and the elegance of Resharper - namely that I wanted real-time syntax checking - so it's slightly bittersweet that Microsoft Source Analysis for C# has been released just as I had completed a working prototype!
So last night - I took my abandoned ReSharper plug-in code and decided to try to integrate it with MSAFC. Below is a screenshot of the result. It's still a little buggy - but hopefully over the next few days I can fix the major issues and release a version to the web.
