25

I want to silence the JSHint warning "attrs is defined but never used" for the variable attrs. However I do not want to use the option /* jshint unused:false */ since this will turn off the warning altogether. I want the warning to be disabled only for attrs.

1 Answer 1

40

For global variables

Add

/* exported variableNameHere */

at the top of your script. In your case, replace variableNameHere with attrs. This tells jshint that attrs will be used elsewhere.

For multiple variables:

/* exported attrs, somethingElse, somethingElse2 */

Docs here.

For local variables

You can ignore all unused local variables within a given function scope using the method outlined in this jshint commit and this GitHub issue. Example:

//jshint unused:true
var a;

function foo(b) {
    //jshint unused:false
    return 1;
}

foo();

// ->
// Line 1: 'a' is defined but never used.

This doesn't seem to be documented anywhere else, but works when tested on http://jshint.com/

3
  • Note::To 'import' it somewhere else you would use /* global attrs, somethingElse, somethinElse2 */
    – Sentient
    Sep 15, 2014 at 19:23
  • 5
    If your issue is with function parameters, you can use /* jshint unused: vars */ as described here. Jul 8, 2015 at 13:14
  • Not working for me either, through "grunt-contrib-jshint": "~0.10.0" Sep 14, 2015 at 20:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.