rfgamaral
rfgamaral

Reputation: 16842

A couple of issues with JSHint: 'is defined but never used' and 'is not defined'

I have this application pretty modular and as such, JSHint is giving me the 'x' is defined but never used error.

My setup goes like this:

app/assets/scripts/bootstrap.js: var x = 5;

app/assets/scripts/kickstart.js: console.log(x);

And here's the output I get from JSHint:

app/assets/scripts/bootstrap.js
  line 1  col 6   'x' is defined but never used.

app/assets/scripts/kickstart.js
  line 1  col 13  'x' is not defined.

2 problems

I know I could us something like /* exported x */ but would be really cumbersome if I have lots of variables like this.

Is there anyway to solve these 2 issues without disabling their specific options? Because they could come in handy in other, more important, situations.

Upvotes: 2

Views: 2822

Answers (1)

sabof
sabof

Reputation: 8192

You can add this at the top of the file.

/*jshint unused: false, undef:false */

Notice that options can be applied to specific scopes. This works for unused, but apparently not for undef.

(function () {
  /*jshint unused: false */

  // Stuff
}());

Upvotes: 3

Related Questions