Is there a way to enforce using tabs instead of spaces?

Viewed 9028

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.

7 Answers

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

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.

Related