views:

633

answers:

9

I have inherited a few programs from a previous developer who was a little sloppy with naming variables, methods and classes with different capitalization and sometimes underscores.

Is there a program or a way in visual studio to validate the naming of each variable, method, property, constant, class.... I would be fine with the standard C# conventions.

+13  A: 

You could look at Microsoft StyleCop and FXCop

jfclavette
What is the difference between StyleCop and FXCop?
Jakob Christensen
StyleCop works at the source level, FxCop works on binaries.
Kent Boogaart
StyleCop == code style enforcement. FxCop (Code Analysis) does not look at source code. It enforces best practices around API design.Oh, and if you're gonna use StyleCop (which you SHOULD) then consider Resharper and StyleCop for Resharper as add-ins that will make your VS.NET life wonderful.
Martin Peck
To my knowledge, StyleCop reads the source code, checking against rules, while FxCop reads the compiled code, checking against rules.
Ben S
StyleCop for this particular instance but FxCop sounds interesting too so thanks for the info
PeteT
+1  A: 

FXCop has that and much more.

Jab
+2  A: 

What you're looking for is StyleCop.

It reads source code to ensure that certain rules are obeyed.

FxCop is used to read the compiled code and generally is not used for this sort of stylistic checking.

Ben S
A: 

FxCop will do the job (or more up-to-date Code Analysis).

Anton Gogolev
no - StyleCop is what's needed to enforce variable naming.
Martin Peck
Visual Studio Code Analysis (FxCop) will check names on "public" methods/classes/properties/etc. What's more, CA is "in the box" with some vesions of Visual Studio, StyleCop is a separate download.
Dan
+2  A: 

Have a look at StyleCop / CodeStyleEnforcer

They'll highlight the bogies but you'll hvae to fix them yourself

http://code.msdn.microsoft.com/sourceanalysis

http://joel.fjorden.se/static.php?page=CodeStyleEnforcer

Eoin Campbell
+1  A: 

FXCop and StyleCop can be used to check for conformance to best practices and standards.

JoshBerke
A: 

This sounds like a job for:

StyleCop

From the website:

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

CraigTP
+4  A: 

I use ReSharper 4.5 for that, which has this advantage, that it allows you to see non-comforming code as you write it.

You also can use NDepend and CQL to check your conventions in a very granular and flexible way. It's great as part of your build script.

Both tools cost money, both are worth it.

Krzysztof Koźmic
+1 for ReSharper 4.5
Richard Ev
http://www.codeplex.com/StyleCopForReSharper marries ReSharper with StyleCop and they live happily ever after
Klas Mellbourn
Yes, but StyleCop has the disadvantage of being too fine grained, and too rigid for my taste. That being said, some of it rules not make sense in every situation and the fact that you cant change them is a FAIL for me.
Krzysztof Koźmic
A: 

As the others have said: FxCop and StyleCop. ReSharper 4.5 also has configurable naming conventions. The beauty of this is that it'll highlight misnamed items and give you a popup with a suggested name. I'm not 100% sure, but I think this can also be run during ReSharper's 'Code Cleanup' functionality (if it's not, it'd be great if it could be!)

Of course, once you edit and and correct the names, they'll only be correct at that very point time in time. To ensure they're correct now and forever more, integrate FxCop/StyleCop into your Continuous Integration environment. This'll catch the naughty anti-social developers who flaunt the rules and regulations (what community service you give them is up to you, but it often involves being the doughnut and/or coffee purchaser 'till someone else screws up!)

Steve Dunn
http://www.codeplex.com/StyleCopForReSharper will configure ReSharper naming to StyleCops conventions
Klas Mellbourn