Posts Tagged jslint

jslint plusplus

Today, my coworker asked why he can’t use ++ operators. I responded that jslint’s plusplus configuration ban it. He certainly was annoyed by such change in the configuration. A quick look into the reasoning behind the ban reveals the following statement from Douglas Crockford’s JSLint – JavaScript: The Good Parts:

The ++ (increment) and — (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling viruses and other security menaces. The JSLint option plusplus prohibits the use of these operators.

Perhaps this ban is necessary for folks who have shown tendencies to develop obscure code in an attempt to deceive or trick others. At the same time, it also bans simple usages such as the one shown below:

var a = 0;
for (var i = 0; i < 5; i++) {
  a = a + i;
}

In order to pass jslint, the for loop may have to look like the following:

var a = 0,
    i;
for (i = 0; i < 5; i = i + 1) {
    a = a + i;
}

Without ++ operators, code will no longer looks the same or as elegant as it used to be. Now that I have my 30 sec on this topic, life goes on with working code! ;)

Comments (1)

JSLint – set exception options

I worked with JSLint today to clean up my local code. While cleaning, I encountered a parameter name that had underscore in its name. JSLint didn’t like this and complained. Since this parameter name was used to communicate with the server and could not be changed, I needed to set an exception in the JavaScript file. This led me to the options section of this page. All I had to do was adding the following line at the beginning of the JavaScript file and JSLint stopped complained about the issue:

/*jslint sub: true */

Comments (1)