使用QUnit运行Grunt时出现JSHint错误

JSHint error when running Grunt with QUnit

本文关键字:JSHint 错误 QUnit 运行 Grunt 使用      更新时间:2023-09-26

我正在使用JSHint和QUnit运行Grunt构建。在我的第一次测试运行中,我得到了以下内容:

Running "jshint:files" (jshint) task
Linting test/libs/qunit-1.11.0.js...ERROR
[L661:C22] W069: ['throws'] is better written in dot notation.
QUnit.raises = assert[ "throws" ];
[L1590:C33] W103: The '__proto__' property is deprecated.
      return obj.__proto__;
Warning: Task "jshint:files" failed. Use --force to continue.
Aborted due to warnings.

除了编辑QUnit源代码和使用——force,我还能做什么?

扩展我的评论,假设Grunt>0.4和Grunt -contrib- JSHint插件,您可以选择特定的文件来运行JSHint。JSHint Grunt插件接受标准的glob模式:

grunt.initConfig({
    jshint: {
        all: [
            'Gruntfile.js',
            'lib/**/*.js',
            'test/**/*.js'
        ]
    }
});
该示例(来自JSHint Grunt插件readme)将选择libtest目录(及其子目录)中的任何.js文件,以及Gruntfile.js文件。我建议将第三方库移出主lib目录。一个常见的约定是为这样的脚本添加一个vendor目录。

如果你依赖的第三方脚本可以通过npm获得,你也可以简单地将它们包含在你的包中。json文件,显然要把node_modules目录从你的Grunt配置中删除。这将取决于你的构建过程,将必要的文件移动到应用程序结构中的正确位置。