【问题标题】:How can I declare globals for jshint to ignore in ember-cli?如何在 ember-cli 中声明 jshint 忽略的全局变量?
【发布时间】:2015-05-04 23:00:24
【问题描述】:

我在我的规范中使用 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.

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: ember.js ember-cli jshint sinon


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您也可以针对每个文件进行设置。例如,我有一个只在服务中使用的库。

      /* global ole*/
      import Ember from 'ember';
      import ajax from 'ic-ajax';
      
      export default Ember.Service.extend({
          //code goes here
      )}
      

      【讨论】:

        猜你喜欢
        • 2014-10-30
        • 1970-01-01
        • 1970-01-01
        • 2014-11-10
        • 2019-11-14
        • 2020-05-10
        • 2018-12-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多