Welcome to EMC Consulting Blogs Sign in | Join | Help

Howard van Rooijen's EMC Consulting Blog (2004 - 2010)

This blog has now moved to http://howard.vanrooijen.co.uk/blog - please update your subscriptions if you wish to receive new content.

Microsoft Source Analysis for C# + ReSharper = Real-time Source Analysis

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.

realtime-source-analysis

Published Thursday, May 29, 2008 2:36 PM by howard.vanrooijen

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Anthony.Steele said:

To be pedantic, if you weren't party to an internal discussion, you're not regurgitating it, you're re-enacting or rediscovering it.

There are times when one layout style has benefits over another due to less typing or easier maintenance, and then there are times when there's little essential difference and everyone doing things the same way is the main benefit.

Some of the rules i would like to see the reasons for. Is putting "using" inside a namespace better than out, or is it just standard? Is putting all private methods seperate from all public methods better than having them grouped by function so that it can be read roughly in order; or is it just pereference?

May 29, 2008 3:58 PM
 

howard.vanrooijen said:

To be even more pedantic, if you are unaware - how can you re-enact or re-discover?! :D

May 29, 2008 4:12 PM
 

Anthony.Steele said:

You re-enact it by having the same arguments that others have already had, you re-dicover it by coming to the same conclusions? "regurgitating" usually implies that you're repeating what you've been told.

There's nothing bad about having the same discussion as others, especially if they had it in private. StyleCop is starting to grow on me, but I may still ask "why?" from time to time.

May 29, 2008 5:08 PM
 

Yamakoa said:

Un truc de fou !

May 30, 2008 3:57 PM
 

SSIS Junkie said:

My learned colleague Howard van Rooijen recently blogged about the new release of Microsoft Source Analysis

June 2, 2008 11:33 PM
 

usarskyy said:

З самого початку думав почати цей пост з слів типу "який я хороший, добрий, мудрий і т.д."... але прийдеться

June 4, 2008 8:11 PM
 

Arpit said:

Howard, why dont you share the plug-in code.... I also use both Resharper and Source Analysis heavily and would love to see a integration....  

June 16, 2008 6:50 PM
 

Dennis C said:

The Source analysis tool looks very interesting, but doesn't seem to work for web projects.. what do you do for those?

July 11, 2008 1:10 PM
 

Ian Shimmings said:

Hi Howard.

I have been experimenting with both products for a while now and would be interested in how you have got on getting the two to work together. I seem to randomly get property pages failing to load (apparently a StyleCop problem now resolved by awaiting release) and am not sure which way to go when the default rules conflict (e.g. the use of "this").

Any news on your plug-in? It would be a useful add-in. If you would like some help knocking it into shape, let me know.

July 30, 2008 10:56 AM
 

Fabrizio said:

I think that your idea to mix refactor and style cop is great.

Colud you share your addin?

August 20, 2008 3:49 PM
 

howard.vanrooijen said:

Hi,

I will publish the source on CodePlex as soon as the StyleCop SDK is released - to ensure that I am not in breach of the StyleCop T&C's - see this post for more details:

http://blogs.msdn.com/bharry/archive/2008/07/19/clearing-up-confusion.aspx

/Howard

August 22, 2008 10:43 AM
 

Colin Nash said:

I have been struggling with how to make Resharper and StyleCop integrate together better and as a first step I just created a plugin for Resharper which highlights any StyleCop violations. If anyone is interested I have hosted in on CodePlex http://www.codeplex.com/RSStyleCopPlugin/.

September 14, 2008 12:15 PM
 

Антон Палёк said:

Еще весной, когда такой продукт как StyleCop увидел этот мир, появилось множество обсуждений о том зачем

October 22, 2008 7:16 PM
 

Anton Palyok блог said:

Еще весной, когда такой продукт как StyleCop увидел этот мир, появилось множество обсуждений о том зачем

October 22, 2008 7:26 PM
 

Палек Антон - персональный блог said:

Еще весной, когда такой продукт как StyleCop увидел этот мир, появилось множество обсуждений о том зачем

November 18, 2008 6:59 PM
 

Howard van Rooijen's Blog : StyleCop for ReSharper on CodePlex said:

February 18, 2009 2:37 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

This blog has now moved - please visit http://howard.vanrooijen.co.uk/blog for new content!
Add to Live.com
Powered by Community Server (Personal Edition), by Telligent Systems