如何禁用警告'define'未使用JSHint和RequireJS定义 [英] How to disable the warning 'define' is not defined using JSHint and RequireJS

查看:667
本文介绍了如何禁用警告'define'未使用JSHint和RequireJS定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用RequireJS AMD。当我在我的项目上运行jshint时,它会抛出错误,如

I uses RequireJS AMD in my project. When i run jshint on my project, it throws error like

在AMD脚本中

 'define' is not defined.

在Mocha测试用例中

In Mocha test cases

 'describe' is not defined.
 'it' is not defined.

如何在jshint中删除此警告?

How to remove this warning in jshint?

推荐答案

为了扩展一下,这里是Mocha的 .jshintrc 设置:

Just to expand a bit, here's a .jshintrc setup for Mocha:

{
  ....
  "globals"   : {
    /* MOCHA */
    "describe"   : false,
    "it"         : false,
    "before"     : false,
    "beforeEach" : false,
    "after"      : false,
    "afterEach"  : false
  }
}

来自 JSHint Docs - false(默认值)表示变量是只读的。

From the JSHint Docs - the false (the default) means the variable is read-only.

如果仅为特定文件定义全局变量,则可以执行以下操作:

If you are defining globals only for a specific file, you can do this:

/*global describe, it, before, beforeEach, after, afterEach */

这篇关于如何禁用警告'define'未使用JSHint和RequireJS定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆