如何在 ember-cli 中为 jshint 声明要忽略的全局变量?

How can I declare globals for jshint to ignore in ember-cli?

我在我的规范中使用了 sinon,并将其包含在 Brocfile 中,如 ember-cli docs 中所述。这行得通,我可以在我的规范中使用 sinon。但是,jshint 抱怨 sinon 没有定义:

1 error: expected false to be truthy
    AssertionError: unit/views/edit-todo-test.js should pass jshint.
    unit/views/edit-todo-test.js: line 11, col 18, 'sinon' is not defined.

我可以通过在规范中将 sinon 声明为全局变量来解决这个问题:

/* global sinon */

但是,我必须将其添加到每个规范中(连同 beforeEachafterEach 等....)。我宁愿只在全局范围内配置一次,但是当我将这些全局变量添加到 .jshintrc 中的 predef 数组时,它们不会被忽略,我仍然会收到错误消息。例如:

.jshintrc:

{
  "predef": [
    "document",
    "window",
    "-Promise",
    "sinon"
  ],
<-- snip -->

仍然失败并显示错误 'sinon' is not defined.

如有任何帮助,我们将不胜感激。谢谢!

您正在编辑错误的 .jshintrc 文件。位于根目录中的那个用于应用程序。

还有一个额外的 .jshintrc 文件用于测试。编辑位于 /tests/.jshintrc.

的那个

您也可以在每个文件的基础上进行设置。例如,我有一个仅在服务中使用的库。

/* global ole*/
import Ember from 'ember';
import ajax from 'ic-ajax';

export default Ember.Service.extend({
    //code goes here
)}