There are a number of ways around this, but the easiest is to use your "one ignore
" like a lifeline. JSLint finally gave in to the fact that some third party libraries are going to send you more parameters than you need, as in this case, I assume, and there's no way to clean things up.
The current solution
To make things clearer on someone reading your code, you can mark one parameter as the ignore
parameter. Combined with Kevin B's observation that you can remove the last parameter, next
, from this function, as it's unused as well, you can use this code to solve your issue:
/*jslint white:true */
/*global router */
router.get('/', function(ignore, res) {
"use strict";
res.render('index', {title: 'JDA POC'});
});
That code works on the newest version of JSLint. ignore
is something of a convention in JSLint, and is used in a couple of different ways.
Just to be overly clear, obviously you can't say function(ignore, ignore, next)
and ignore two params, because you're "redefined ignore
" at this point. So this solution is very limited, and doesn't work in some cases.
The old solution
Unfortunately, that code doesn't link on the older version of JSLint, which is what most people still use to lint their code!
There, you're stuck with the unparam declaration, though I'd suggest still cleaning off next
and using the what-will-work-soon ignore
convention.
/*jslint white:true */
/*global router */
/*jslint unparam:true */
router.get('/', function(ignore, res) {
"use strict";
res.render('index', {title: 'JDA POC'});
});
/*jslint unparam:false */
The insane old solution, which is more common than you'd think
Other people have gone absolutely bat-crazy writing convoluted wrappers so this isn't an issue. I hate that, but here's an example for completeness (I think this kind of junk is why Crockford added the ignore
param):
/*jslint white:true, sloppy:true */
/*global router */
function convolutedRearrangementHack(res) {
res.render('index', {title: 'JDA POC'});
}
router.get('/', function(req, res, next) {
convolutedRearrangementHack(res, req, next);
});
I mean, that lints, but it's horrible. Sometimes you can use this successfully-ish by creating your own wrappers grouped in a single, global namespace, but I don't like getting any farther from my third party libraries than I have to.
Critique of JSLint ;^)
Personally, I'm not sure ignore
is that much clearer than using the names the function signature expects. I'll admit this is one JSLint rule I'm not 100% convinced is as useful as its alternatives. That is, everyone knows what jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
is, even if they only want the errorThrown
, but only folks who understand the inner workings of JSLint understand why you might have ignore
in your param list. I think there's value in using the well-known function signature when interfacing with third party libraries.
Seems JSLint should see when a function is being called on a declared global
object and not complain, or at least have an option to say that certain global
entries are objects outside of your control.
The post scriptum suggestion
EDIT: If router.get
is code under your control, and there's use case for using only req
, consider refactoring the order of parameters so that they match use priority order. I'll give Crockford that that isn't an unuseful practice (heavy hedging, I know!).