Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have been validating my JavaScript using JSLint for about 2 years now and once in a while there are rules that change. In general when JSLint introduces a new rule, there is a checkbox to ignore this rule when parsing, or if you choose to not ignore it then to make your code compliant to it.

As I was running my JSLint validation today, however, I run into these two new errors:

Use spaces, not tabs.

This is not the "mixing of tabs and spaces" error. I am using only tabs. This is a recently modified version of "mixing of tabs and spaces" which now disallows tabs in general.

And:

Unsafe character.

*/

Unsafe character.

_const: {

There are no new options to ignore. I cannot understand what is unsafe about closing a block comment, why it considers _const: { as unsafe when I have nomen: true, (dangling _ in identifiers) or why should I be suddenly switching from spaces to tabs, when I still have the configuration about indentation of 4 spaces being a tab.

Does anyone have an idea why those were introduced to at least how to make JSLint ignore these new rules?

Update: The Messy White Space option works around the issue but it would cause other unexpected behavior:

if (condition) {    //            ^-- there is a space but it won't indicate an error 
like image 715
Konstantin Dinev Avatar asked Dec 17 '12 11:12

Konstantin Dinev


People also ask

Why use spaces instead of tabs?

Their research found that spaces were far better for a number of different reasons. Not only is this technique more visually appealing, it allows programmers to make more money. The analysis performed by the team at Stack Overflow found that programmers who use spaces instead of tabs are making more money.

How do you fix error mixed spaces and tabs no mixed spaces and tabs?

Go to view option then go to indentation and you will find indent using space . Your problem should be fixed. If it is not fixed then go to convert indention to spaces .


2 Answers

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.

like image 72
James Allardice Avatar answered Sep 17 '22 22:09

James Allardice


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

like image 34
mathius1 Avatar answered Sep 16 '22 22:09

mathius1