If you use tabs, you can check that files are okay by forbidding /^\t* /.
If you use tabs for indentation, spaces for alignment, ??????
I'm sure there is a command-line pre-commit formatter I could use. But I have never tried to set it up, since I can reformat existing code with a couple of keystrokes in my editor.
Most editors have code structure parsing of some kind built-in for tabbing already. E.g. pressing the <tab> key indents the current line to match the structure of surrounding code (or cycles between valid indents for something like Haskell or Python). So they know the difference between initial indentation (that people want to be able to configure visually) and alignment.
<TAB><TAB>function name(arg1, arg2,
<TABs or spaces?????> arg3 <-- align with arg1)
The other issue is with maximum line length. If you have a maximum line length of 80, do tabs count as 2 spaces, 4 spaces, or 8 spaces towards meeting that line length?Using spaces ensures that it at least looks consistent, independent of your tabstop settings.
<TAB><TAB>function name(arg1, arg2,
<TABs or spaces?????> arg3 <-- align with arg1)
Just wondering… do you realign the parameters every time you rename a function?I agree that this kind of indentation might not make sense on a collaborative project because different people have different standards, but if I'm the only one working on a piece of code I really think precise alignment makes the code a lot more readable.
<TAB><TAB>function name(
<TAB><TAB><TAB>arg1,
<TAB><TAB><TAB>arg2,
<TAB><TAB><TAB>arg3,
<TAB><TAB>)
That means this never comes up, and you don't need to change adjacent lines because you've renamed a function. function name(arg1, arg2, arg3,
arg4, arg5, arg6); <TAB><TAB>function name(<TAB>arg1, arg2,
<TAB><TAB><TAB>arg3)Really this is a peculiar kind of OCD. You don't need to have arg3 precisely lined up with arg1. Or better yet, indent all the arguments in a nice column - if there's so many that they can't fit horizontally, render them vertically. Most IDEs default to two indentations for continuation.
Them: "We have to use these tools to avoid disagreements about spacing and formatting choices".
Me: "But... I wasn't having any in the first place. It's only the 3 of you that were having these disagreements. And now you're spending ridiculous time planning reformat of entire codebase, instead of actually... moving the project forward.
Please don't bitch about me using $x = new Temp(); in a test file. I'm the only person on the project even making test files, and you're blocking my TEST file because you don't like variable name style..."
They got in to a quandary when trying to inline some JS in to a PHP view file. The PHP standard is 4 spaces, and the person doing some of the JS had defined 2 spaces for JS ("so we can all agree on it") and ... all hell broke loose trying to determine what the style/formatting should be for JS-inside-PHP files. 4 spaces? 2 spaces?
<TAB><TAB>function name(arg1, arg2,
<TAB><TAB> arg3)So in this case:
<TAB><TAB>function name(arg1, arg2,
<TAB><TAB> arg3
since we were talking about indention, not alignment, I don't see how anything changes. If I want my indent to be 3 spaces and you want 8, we can set our tab width and arg3 will still be aligned correctly for both of us.Or you live with misaligned arguments (its a bit of a smell imho to have so many arguments that you need to split them over many lines, although it for sure does happen) and just use tabs for both.
My main point is that with tab, each individual has some control over their preferences, even if not perfect for alignment, while with spaces everyone has to live with the standard and nobody has control over their preference. That is, tabs is "mostly people get what they want", spaces is "nobody gets what they want unless they happen to want the style guide imposed on them". The former seems a lot better to me!
I'd rather drop the insertion part and have my editor handle adding an appropriate number of spaces.
Let me add this: there's actually nothing stopping you from displaying a four-space indented file as a two-space indented file. Just parse, replace indentation-dictated groups of four spaces with two spaces, you're done.
I don't know of a plugin that does this for $your-favorite-editor but it's, y'know, software. There's nothing which prevents it.
Which is a ton more hassle than inserting tabs.
You could always make CapsLock insert a tab character so you keep the functions of the tab key separate from inserting a tab.