JSLint reports "Unexpected dangling" character in an underscore prefixed variable name

JavascriptJslint

Javascript Problem Overview


I know that some people consider the presence of a leading underscore to imply that a variable is "private," that such privacy is a fiction, and assume this is why JSLint reports such names with an error message.

I use Google Analytics on a Web site I am building. I make reference to GA's variables, such as "_gaq."

I am trying to get my JS code to be 100% JSLint clean (I'm not religious about my coding style, and so will go with Mr. Crockford's counsel). That said, I can't do anything about Google's variables names... so, I guess I can't get 100% "clean."

I post here in case I've misunderstood the message, and can do something to comply with JSLint practices.

Javascript Solutions


Solution 1 - Javascript

Ah, I've got this handled... I wrap the statements that use the underscore prefixed variables with JSLint commands to disable, then re-enable this class of error:

/*jslint nomen: true*/
... statement(s) with _var ...
/*jslint nomen: false*/

Solution 2 - Javascript

The best way to handle this is just to enable the "Tolerate dangling _ in identifiers" (nomen) option. See http://www.jslint.com/lint.html for details...

Solution 3 - Javascript

JSLint is just a code quality tool. Not completely passing its tests does not mean your code is bad; it simply means you don't follow all the conventions laid out by its creator. Although JSLint makes very good suggestions, it is not always possible to fulfill them all, especially when using someone else's library which was not tested against it. Rather than littering your source code with meaningless meta-comments, you should check your code with the "Disallow dangling _ in identifiers" option disabled, since it seems not to makes sense to use with your particular code.

Solution 4 - Javascript

I use JSLInt with node.js. You can pass --nomen flag to get around this feature

jslint --nomen myfile.js 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZhamiView Question on Stackoverflow
Solution 1 - JavascriptZhamiView Answer on Stackoverflow
Solution 2 - JavascriptscruffianView Answer on Stackoverflow
Solution 3 - Javascriptuser422129View Answer on Stackoverflow
Solution 4 - JavascriptJaseemView Answer on Stackoverflow