views:

149

answers:

3

StyleCop offers to check for consistent use of spaces, but sadly lacks the opposite idea: Force source code to use tabs. Is there some way to add this functionality? It does not have to be StyleCop, other tools are welcome as well.

A: 

Do it within your source control server. Use a pre-commit script to check the file for lines starting with multiple spaces and prevent the commit.

I agree tabs are better than spaces. It's a personal preference, but team consistency is very important.

Sam
A: 

One thing you could do, assuming you are using Visual Studio as your IDE, and that your team-mates buy-in to this idea, would be to set VS to use tabs instead of spaces, export and share the settings file.

The setting can be found under Tools > Options > Text Editor > All Languages (or the language you wish to use) > Tabs and then on the right hand side you can pick to 'Insert Spaces' or 'Keep Tabs'.

To export the settings from your visual studio: Tools > Import and Export Settings > Export selected environment settings > select the 'Options'

Just a thought - but to be honest the real problem seems to be the buy-in from your team-mates. They can always revert back to their settings otherwise. Alternatively, upon check-in, as Sam suggested, you can do some automated re-formatting.

HTH

FOR
+1  A: 

StyleCop supports creation of custom rules, so you can add your own "use leading tabs instead of spaces" rule. If you don't feel like trying to develop your own, you can get an existing rule at either http://stylecopcontrib.codeplex.com/ or http://github.com/AArnott/nerdbank.stylecop.rules.

Nicole Calinoiu