I’m trying to keep a jslint exclusion as close to the error as possible to not hide any errors by mistake. The unused parameter in the example is x in function f2 and I would like to only exclude this occurrence.
The first example, excluding 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*/
Surrounding the var statement also works, but will hide 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 one generates an error: “Expected an identifier and instead saw ‘/*jslint’ (a 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 are you allowed to have jslint directives?
Only excluding one of the functions in the same var declaration is not possible. As said in the comment, only complete statements can have jslint directives; ended up with the following: