简体   繁体   中英

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.

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
}());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM