Prevent JSHint warning that 'functionName is defined but never used'
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
I had this problem with should
and expect
in Chai tests. I ended up with this pattern:
'use strict';
var request = require('supertest');
var should = require('chai').should(); // jshint ignore:line
var expect = require('chai').expect; // jshint ignore:line
process.env.NODE_ENV = 'test';
var appPromise = require('./index');
describe('GET /r_u_up', function() {
it('respond with 204', function(done) {
appPromise.then(function(app) {
request(app)
.get('/r_u_up')
.expect(204, done);
});
});
});
You can simply use
"unused": false,
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:
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": false, // the change is here
"boss": true,
"eqnull": true,
"node": true
}
set the "unused"
to false
.