gruntjs - grunt-contrib-jshint 不会提示 console.log

标签 gruntjs jshint

通过以下设置,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/

相关文章:

javascript - ERR_ADDRESS_UNREACHABLE 在 Chrome Android 中打开我的本地主机

gruntjs - 使用 es6 进行 Grunt 配置

javascript - 使用现有的 Grunt 项目 - 获取 JSHint 缺少分号和错误

javascript - JShint 警告 : jQuery plugin marked incorrectly 'defined but never used' in AMD

javascript - 将 JSLint/Hint 与 requirejs 一起使用

javascript - Grunt.js 设置绝对路径

node.js - 获取 0 :0 Bad option : 'varstmt' for first line in all files

javascript - 将 @author 的使用视为代码风格违规

javascript - 从终端在 grunt 中实现 const

javascript - 如何禁用警告 'define' 未使用 JSHint 和 RequireJS 定义