[英]Prevent JSHint warning that 'functionName is defined but never used'
我刚开始使用JSHint(通过Sublime-Linter包用于Sublime Text 2)。 我想抑制它在定义之前使用的函数的警告,因为我发现使用这样的函数定义没有问题。 例如,以下代码生成警告:
(function($){
$(document).ready(function()
{
formValidationSetup();
refreshErrorMessages();
});
function formValidationSetup()
{
}
function refreshErrorMessages()
{
}
})(jQuery);
警告:
- formValidationSetup已定义但从未使用过
- refreshErrorMessages已定义但从未使用过
我已经尝试在JSHint选项中将undef设置为false ,但我仍然遇到这些错误。 我应该设置另一种选择吗? 形成undef的JSLint文档 :
如果在使用之前不需要声明变量和函数,则为true。 这在严格模式下不可用。
避免警告
定义但从未使用过
在你的javascript中的jslint中添加评论:
/*exported formValidationSetup, refreshErrorMessages */
在jshint和jslint中,您可以将未使用的选项设置为false:
/*jshint unused:false*/
请参阅选项
我在Chai测试中should
和expect
这个问题。 我最终得到了这种模式:
'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);
});
});
});
你可以简单地使用
"unused": false,
在你的.jshintrc中
在典型的Yoeman设置中不接触Gruntfile.js
更好方法是编辑.jshintrc
文件(Unix系统中的隐藏文件)。 并按以下方式更新内容:
{
"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
}
将"unused"
设置为false
。
有趣的是,添加'use strict';
IIFE内部抑制了错误。 不知道为什么。
你会想要使用'latedef'选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.