JSHint giving 'Read Only' error for reassignment of $

Spencer Carnage picture Spencer Carnage · Dec 13, 2011 · Viewed 7.9k times · Source

I'm using the node-jshint command line to lint all of my JS files. I'm doing a reassignment of the $ by:

$ = someWindowObj.document.id;

and its giving me the error "Read Only." I am using Mootools so I am setting the option mootools to true. When I turn the option off in the file itself, via /*jshint mootools:false*/ I'm still getting the error. Shouldn't disabling the mootools (or jquery) option also disable the error? When I remove the mootools option completely from the ~/.jshintrc and the JS file, the error doesn't report.

I'm not sure if this is a bug or the intended behavior so I thought I put it to SO before submitting a bug.

Answer

Anton Kovalyov picture Anton Kovalyov · Dec 14, 2011

If the project settings overwrite in-file settings you should file a bug report for the node-jshint project. In the meantime, you can always do /*global $:true */. This tells JSHint that it is okay to overwrite $ global variable.