通过以下设置,jsHint 不会提示 console.log
语句,同时仍报告 debugger
语句:
jshint: {
files: [
'Gruntfile.js',
'js/**/*.js',
'tests/*.js',
],
options: {
curly: true,
immed: true,
noarg: true,
expr: true,
quotmark: 'single',
maxdepth: 3,
browser: true,
eqnull: true
}
},
最佳答案
据我所知,JSHint 从未警告过对 console
的引用。其中没有专门处理此类引用的代码。
console
被简单地视为一个标识符,应该从它引用的任何上下文中定义和访问它(这是正确的,因为这实际上就是它的全部)。
因此,您可以通过让 JSHint 警告所有 undefined variable 来警告控制台的使用情况。只需将 undef
选项设置为 true
。
然后,如果您想允许使用 console
,您可以将其添加到 globals
指令中或将 devel
选项设置为true
(隐式地将其添加到您的 globals
指令中)。
关于gruntjs - grunt-contrib-jshint 不会提示 console.log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16336556/