A Comparison of JavaScript Linting Tools

Who knows what else? We can all know as the code provides us with the details. Doing a search for the word white reveals all.

Line numbers (after Chrome pretty-print)
155 - allowed options
242 - expected at column
258 - use spaces, not tabs
318 - unexpected character
1005 - expected space (one space)
1012 - expected space (one space only)
1019 - unexpected space (no space)
1026 - unexpected space (no space only)
1031 - missing space
1043 - no comma space then to 1026
1054 - no semicolon space then to 1026
2614 - expect case at same column as switch

The following code examples are poor code, to demonstrate the different JSLint white space warnings that are triggered within the code.

Expected x at column

var x = true;
 if (x) {
    x = false;
}

Use spaces, not tabs

var x = true;
if (x) {
	x = false;
}

Unexpected character (spaces on blank line)

var x = true;
    
if (x) {
    x = false;
}

Expected space

var x = true;
if(x) {
    x = false;
}

Expected only one space

function example() {
    "use strict";
    return  '';
}

Unexpected space

var a = ( 1 + 2);

Unexpected space where only none should be

var a = -[0 , 1];

Missing space

var x = true;
if (x){
    x = false;
}

Expect case at same column as switch

var expr = "Oranges",
    msg;
switch (expr) {
    case "Oranges":
        msg = "Oranges are $0.59 a pound.";
        break;
    case "Apples":
        msg = "Apples are $0.32 a pound.";
        break;
    default:
        msg = "Sorry, we are out of " + expr + ".";
}

Also, there’s a handy jslinterrors site that can be handy too, which was only used to retrieve some suitable coding examples for common issues.

I don’t know about you but I would learn about why tabs cause such as issue compared with spaces, and proceed to resolve the problem which can be easily and rapidly done across all code-bases with the right tools.