StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools.
The goal is to define guidelines to enforce consistent style and formatting and help developers avoid common pitfalls and mistakes.
StyleCop contributes to this maintainability by encouraging consistency of style, which in turn makes it easier for developers to pick up existing code and work with it productively, and by encouraging plenty of documentation for future developers to read thereby improving the long term maintainability of the source.
Historically, different development groups have used drastically different coding styles. Many teams have used inconsistent coding styles within a single product or even a single source file. StyleCop was originally written to provide a simple and efficient way to enforce a common coding style for C# code throughout Microsoft.
Over time, StyleCop evolved to include new rules that go beyond style checks. StyleCop has become a good complement to FxCop (Code Analysis). FxCop analyzes compiled .NET binaries, while StyleCop analyzes the original source code. This allows StyleCop to investigate issues in code that are thrown away by the compiler. StyleCop could also be used to investigate issues in non-compiled languages such as JavaScript or Xml.
StyleCop provides an extensibility mechanism allowing parsers and analyzers for any language to be plugged into the system. Individual developers or teams can write and deploy their own rules, or integrate support for new languages. The StyleCop SDK provides support for writing StyleCop add-ins.