Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent JSHint warning that 'functionName is defined but never used'

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:

  1. formValidationSetup is defined but never used
  2. 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.

like image 472
Undistraction Avatar asked Sep 26 '12 17:09

Undistraction


People also ask

How do I ignore JSHint warning?

In October 2013 jshint added a way to ignore blocks of code like this: // Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */ // Code here will be linted with JSHint.

What is JSHint used for?

JSHint is a static code analysis tool used in software development for checking if JavaScript source code complies with coding rules. JSHint was created in 2011 by Anton Kovalyov as a fork of the JSLint project (by Douglas Crockford).


1 Answers

To avoid the warning

defined but never used

in jslint in your javascript add comments like:

 /*exported formValidationSetup, refreshErrorMessages */ 

In jshint and jslint you can set the unused option to false:

 /*jshint unused:false*/ 

See Options

like image 60
Roland Puntaier Avatar answered Sep 30 '22 13:09

Roland Puntaier