Stopping JSHint Not Defined (W117) Messages

Posted: November 8, 2015 in ASP.Net
Tags: , , ,

The JSHint component of Visual Studio’ Web Essentials will point out plenty of problems with your JavaScript code, sometimes though some of the messages are not useful.

For example, if you are using Kendo UI in your project, you will get a message “‘kendo’ is not defined” for each instance of a kendo component in a given JS file.

It is possible to configure your user settings to turn off the warning for Kendo or other such libraries, but that setting is not part of the project, so other users will see the same warning if they don’t have the exclusion.

To turn it off in code, one can simply add the following comment to their JS file(s):

//the comment below will disable the JSHint about Kendo being undefined
/*global kendo*/

Only the “/*global XXX*/” part is required, the “//” comment is included for clarity.

Depending on the frequency of usage of a library and your tem preferences, it may make more sense to turn the message off in settings, but this is a quick and portable solution for one-off  scenarios.

Comments are closed.