Alternative to StyleCop for Visual Studio?

mmcdole picture mmcdole · Nov 13, 2008 · Viewed 8.4k times · Source

I like StyleCop's static code analysis and rules enforcement. However, it is severely lacking in several key departments.

  • Adding new rules isn't officially supported and from what I hear pretty difficult.
  • Automatic "fixing" of trivial rules violations would be nice! Perhaps not with variable naming but with method ordering (static, etc) this would be a huge time saver.
  • Microsofts "one-size-fits-all" approach to StyleCop is kind of restrictive. I would like to have a custom set of rules for our in-house standards.

Is there such a commercial product out there?

alt text http://blogs.interakting.co.uk/images/blogs_interakting_co_uk/dominicz/WindowsLiveWriter/MicrosoftStyleCopSourcecodeanalysisforfo_D8EF/styleCopErrors_6.gif

Answer

Bevan picture Bevan · Nov 14, 2008

Adding rules is, or is going to be, officially supported:

As promised, we will also be releasing SDK documentation for StyleCop explaining how to author custom rules and how to integrate the tool into custom build environments. The SDK documentation is currently under final review and we hope to release it very soon. -- JasonAll

In terms of our "in-house" style, I got pretty close by disabling a handful of StyleCop rules:

  • File Headers (SA1633-SA-1640)
  • Code ordering (SA1200-SA1202)
  • Requiring "this" (SA1101)

You can do this globally by modifying the Settings.StyleCop file in the installation directory, though I've taken the approach of putting one at the root of our source tree in each project.

The end effect is much what we want. There are a handful of "in-house" choices that would be nice to flag, but even without them StyleCop is delivering a lot of value for us.