What rules do jslint built-in directives define?

I am trying to keep the jslint exception as close to the error as possible so as not to hide the errors by mistake. The unused parameter in example x in function f2 , and I would like to exclude this event only.

The first example, with the exception of the surrounding function, works, but will hide other errors, if any:

 /*jslint unparam: true*/ function test1() { var f1 = function (x) { alert(x); }, f2 = function (x) {}; f1(0); f2(0); } /*jslint unparam: false*/ 

The surrounding var statement also works, but hides errors in f1 :

 function test2() { /*jslint unparam: true*/ var f1 = function (x) { alert(x); }, f2 = function (x) {}; /*jslint unparam: false*/ f1(0); f2(0); } 

This generates an error: "The expected identifier and instead saw" / * jslint (reserved word). "

 function test3() { var f1 = function (x) { alert(x); }, /*jslint unparam: true*/ f2 = function (x) {}; /*jslint unparam: false*/ f1(0); f2(0); } 

The question is, where in the source code can you have jslint directives?

+4
source share
1 answer

Only the exception of one of the functions in the same var declaration is not possible. As the comment says, only complete statements can have jslint directives; The result is the following:

 function test4() { var f1, f2; f1 = function (x) { alert(x); }; /*jslint unparam: true*/ f2 = function (x) {}; /*jslint unparam: false*/ f1(0); f2(0); } 
+6
source

All Articles