Why were the new JSLint errors "use spaces, not tabs" and "unsafe character" introduced?

Well it looks like Douglas Crockford just made a whole lot more people switch to JSHint. Have a look at this commit.

The "Mixed spaces and tabs" error has been removed, and a new "Use spaces, not tabs" error has been added in its place. Aside from that, there's one tiny change in that diff that shows the cause of this. The following line (comment added):

at = source_row.search(/ \t/);
//                      ^ Space

has been replaced with this:

at = source_row.search(/\t/);
//                      ^ No space!

Following that search there's an if statement. If the condition evaluates to true, the "Use spaces, not tabs" warning is issued. Here's that statement:

if (at >= 0) {
    warn_at('use_spaces', line, at + 1);
}

I hope that this is just a little oversight by Crockford. As you can see, JSLint is now going to raise this warning if you use a tab character anywhere. Unfortuately, his commit messages are completely useless, and the documentation doesn't appear to have been updated, so I can't do anything other than speculate as to the reasons behind this change.

I suggest you abandon JSLint and switch to JSHint right now.


You can suppress the error by clicking the "messy white space" option.


To answer why JSLint now gives an error about tabs, http://www.jslint.com/help.html gives this justification:

Tabs and spaces should not be mixed. We should pick just one in order to avoid the problems that come from having both. Personal preference is an extremely unreliable criteria. Neither offers a powerful advantage over the other. Fifty years ago, tab had the advantage of consuming less memory, but Moore's Law has eliminated that advantage. Space has one clear advantage over tab: there is no reliable standard for how many spaces a tab represents, but it is universally accepted that a space occupies a space. So use spaces. You can edit with tabs if you must, but make sure it is spaces again before you commit. Maybe someday we will finally get a universal standard for tabs, but until that day comes, the better choice is spaces.

Essentially he wants everybody to come to a consensus on whether to use tabs or spaces to prevent them from ever being mixed. He's decided that the consistency of the width of a space makes it the superior choice, so we should all use that. Clearly some people will disagree with this line of thinking (myself included), but that is the reason why JSLint throws that error.


Depending on your editor/IDE you can adjust how TAB works.

For instance, I use Sublime Text. Near the bottom right corner there is a Tab Size : 4.

I clicked on it and set it 'Indent Using Spaces'.

This updated all my Tabs to use spaces and JSLint errors disapeared. I try to use as few options as possible with JSLint as I want my code to be well structured.

I also use JSFormat, which will tab based on my editors settings, so whenever I'm done I run my JSFormat, then JSLint. No errors = happy boy!

Hope it helps.