Sunday, May 8, 2011

Cop? What the hell did I do wrong?

This document explains a little introduction on the StyleCop tool to check on code conventions of our .Net projects.

Style convention can be tedious if done manually. For .Net code convention I prefer the one set by Mike Kruger from SharpDevelop team. But as I've said, it is so much for a manual task, especially if you're taking a project previously done by lots of people and with no standards.

Then came StyleCop. I mean I just use StyleCop because I'm on .Net. Java has CheckStyle, so for other platform/languages you might want to check Google or Wiki.

Introduction to StyleCop

Hmmm. I'm not really a type of person that gives lots of introduction so let's move on...

Installation and Configuration

First off, download StyleCop here. Install it and you're done!

Ok you're not. Well, let's move on. Before using StyleCop, we need to have an IDE. Yepey! We're getting to code. Of course, we have that right? I use SharpDevelop and if you don't use it, nevermind, installing StyleCop with VisualStudio automatically gets VS to have Run StyleCop when right clicking on projects. But that's another issue. I'm with SharpDevelop so we're moving to getting started with it. No VisualStudio, please!

Open SharpDevelop and to to Tools->Options and click on Tools. Click on Source Analysis and find your StyleCop installation directory. Now, right click on your project and Check with StyleCop. That's it, you're done. Really, you're done!









































But, if you really have to edit the settings. Settings are usually bunch of those configurations set by Microsoft for C# code convention. Oh, didn't I tell you from the time of writing StyleCop only supports C#? Now you know. No VB, who cares? Anyway, you can find your global settings on your StyleCop installation directory. Double click on the Settings.StyleCop (usually in C:\Program Files\Microsoft StyleCop 4.3.3.0) and edit it the way you want it. Have fun!