views:

1369

answers:

5

I've decided to start running StyleCop on a medium sized project and am getting over 1000 warnings.

Is there a quick easy way to fix most of these warnings? Most of the warnings could easily have been automated to resolve and would save me a lot of time.

A: 
  1. Turn off the warnings! Not recommended, but you could use this in the short term until you get a bulk of the issues resolved.
  2. Write a program to fix some of the simpler warnings, or use find/replace
  3. Use code snippets to help with things like file header documentation

There was mention on the StyleCop blog regarding implementing auto fixing for rules

Also check out the entry on the blog regarding integrating in to an existing large project.

Note: It seems that StyleCop only returns around 1000 warnings, so you will continue to get this number even after fixing a heap.

benPearce
If you are going to downvote something, it seems only fair to provide an explanation if the reason is not obvious.
benPearce
+4  A: 
Robert Cartaino
Set up your code cleanup profile, and you can use CTRL + E + F to automatically reformat any file to fix all errors.
Greg Beech
(That's a R# thing anyway, but with StyleCop-4-ReSharper it also fixes style violations).
Greg Beech
A: 

Unfortunately, right now, I don't know of any automatic tools to fix things entirely.

However, if you setup Visual Studio's formatting options (and Resharper's, if you have that) for code formatting to match the style cop guidelines, cleanups get a bit easier.

Once you've done that, you can go into a file and do Edit->Advanced->Format Document (or the keyboard shortcut, which varies with your shortcut settings - mine is Ctrl+K, Ctrl+D). This will fix quite a few of the style cop warnings, especially if you have resharper + the stylecop plugin. It won't fix all of them, but in many cases, it's taken the number of warnings in a file from hundreds down to tens.

Reed Copsey
A: 

If you have Resharper you can download a StyleCop plugin for Resharper which features some automatic fixes. StyleCop for Resharper on codeplex.

marklam
A: 

There is a project in codeplex which does some automatic fix based on stylecop warning. It is not complete however...

see: http://stylefix.codeplex.com/

Samuel