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

时间:2013-05-19 22:01:15

标签: javascript qunit gruntjs jshint

我正在使用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 之外,我该怎么办?

1 个答案:

答案 0 :(得分:2)

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

grunt.initConfig({
    jshint: {
        all: [
            'Gruntfile.js',
            'lib/**/*.js',
            'test/**/*.js'
        ]
    }
});

该示例(来自JSHint Grunt插件自述文件)将选择 lib test 目录(及其子目录)中的任何 .js 文件),以及 Gruntfile.js 文件。我建议将第三方库移出主 lib 目录。常见的惯例是为此类脚本添加供应商目录。

如果您所依赖的第三方脚本可通过npm获得,您也可以将它们简单地包含在 package.json 文件中,并且显然将 node_modules 目录保留在你的Grunt配置。然后由您的构建过程将所需的文件移动到应用程序结构中的正确位置。

相关问题