JSLint Messages – Nested Comment

I stumbled across this message recently during the course of developing a bespoke jQuery plugin for one of our systems.

The offending code in question was

/*****************************************************************************/
/*Private functions.
/*****************************************************************************/

Given its structure, I found myself blinded to the offending code until I spotted that I had indeed omitted the closing ‘*/’ from the second line.

The message it yielded in full was:

Stopping, unable to continue. (4% scanned).

This message is easy enough to understand, but it’s one of those that causes JSLint to halt in its tracks

The omission of a closing statement to any block of code can result in inadvertently nesting any proceeding code. Block comments are more forgiving of the omission, because the second opening ‘/* will be treated as a comment itself.

However, consider the following:

/*Private functions.    /*Nested Comment*/   */

In the above code, the first close-comment will close everything, and the second will be left dangling. This is even shown up by the syntax-highlighter (if you can see it).

One user did ask this question of Douglas Crockford, who responded

JSLint stops because it sees comments that are nested. That is usually
an indication of a serious coding error. In the face of such errors,
JSLint stops.

So there we have it. Don’t nest your comments.

This article is one of a series on the error and warning messages produced by JSLint.

Leave a Reply