我刚刚开始使用JSHint(通过Sublime-Linter包用于Sublime Text 2)。我想抑制它在定义之前使用的函数的警告,因为我发现使用这样的函数定义没有问题。例如,以下代码生成警告:
(function($){
$(document).ready(function()
{
formValidationSetup();
refreshErrorMessages();
});
function formValidationSetup()
{
}
function refreshErrorMessages()
{
}
})(jQuery);
警告:
- formValidationSetup已定义但从未使用过
- refreshErrorMessages已定义但从未使用
醇>
我已尝试在JSHint选项中将 undef 设置为 false ,但我仍然遇到这些错误。我应该设置另一种选择吗?形成 undef 的JSLint docs:
如果在使用之前不需要声明变量和函数,则为true。这个 在严格模式下不可用。
答案 0 :(得分:88)
避免警告
已定义但从未使用过
在你的javascript中的jslint中添加评论:
/*exported formValidationSetup, refreshErrorMessages */
在jshint和jslint中,您可以将未使用的选项设置为false:
/*jshint unused:false*/
请参阅Options
答案 1 :(得分:9)
我在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);
});
});
});
答案 2 :(得分:3)
您只需使用
即可"unused": false,
你的.jshintrc 中的
答案 3 :(得分:2)
有趣的是,在IIFE中添加'use strict';
会抑制错误。不知道为什么会这样。
答案 4 :(得分:2)
在典型的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
。
答案 5 :(得分:-2)
您需要使用'latedef'选项