Sergey Shishkin

on agile software development

StyleCop: Source Analysis Tool for C#

Recently Microsoft has finally released its internal source analysis tool for C#StyleCop. Another analysis tool—FxCop—validates compiled assemblies for conformance to the Framework Design Guidelines. StyleCop goes further and analyses source code files against many coding style rules:


The rules are not very flexible. You can only disable particular rules and narrow the scope of some rules (like require XML docs for public and protected elements only). But you cannot for example choose whether you like tabs or spaces for indentation—StyleCop does not allow tabs. Other debatable rules are "Field Names Must Not Contain Underscore" and "Prefix Local Calls With This".

I find quite interesting the position of MS in the rules debate. I would summarize it like "It is an internal tool, not a product. Use it as is. We don’t care if it doesn’t fit your organization":

Source Analysis originated as an internal Microsoft tool, which we have decided to release externally so that others can take advantage of it as well, if they would like to. The limited customization of the prefix rules is deliberate, in order to maintain a consistent style across a very large codebase.

At least StyleCop supports writing your own rules. Though MS does not like it:

Please keep in mind that disassembly of the tool or distribution of the source for this tool is a violation of the license that you agreed to when you installed the tool. The license appears during installation.

What?! I really don’t understand yet what MS is going to do with this tool. Their potential strategy could be to use StyleCop and its not flexible rules to force their own coding style among the developers. Organizations will either use the tool as is, or go their own way without any tool to enforce coding guidelines, or without any coding guidelines at all.

Anyway, StyleCop is a great tool helping you to enforce your coding guidelines. Because without control any guideline means nothing. And it can even be integrated into your team build.

Technorati Tags:

Written by Sergey Shishkin

28.05.2008 at 19:04

Posted in Uncategorized

%d bloggers like this: