I have just started using JSHint (through the Sublime-Linter package for Sublime Text 2). I would like to suppress its warnings regarding functions that are used before they are defined, as I see no problem with using function definitions like this. For example, the following code generates warnings:
(function($){
$(document).ready(function()
{
formValidationSetup();
refreshErrorMessages();
});
function formValidationSetup()
{
}
function refreshErrorMessages()
{
}
})(jQuery);
The warnings:
- formValidationSetup is defined but never used
- refreshErrorMessages is defined but never used
I've tried setting undef to false in the JSHint options, but I'm still getting these errors. Is there another option I should be setting? Form the JSLint docs for undef:
true if variables and functions need not be declared before used. This is not available in strict mode.
You can simply use
in your .jshintrc
Interestingly, adding
'use strict';
inside the IIFE suppresses the error. Not sure why though.A better way not touching the
Gruntfile.js
in a typical Yoeman setup is to edit the.jshintrc
file (a hidden file in Unix system). And update the content as the following:set the
"unused"
tofalse
.You'll want to use the 'latedef' option
I had this problem with
should
andexpect
in Chai tests. I ended up with this pattern:To avoid the warning
in jslint in your javascript add comments like:
In jshint and jslint you can set the unused option to false:
See Options