如何告诉JSHint忽略一个文件中的所有未定义变量? [英] How to tell JSHint to ignore all undefined variables in one file?

查看:155
本文介绍了如何告诉JSHint忽略一个文件中的所有未定义变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Karma测试中,有许多全局变量和函数,JSHint抱怨它(它被集成到我的编辑器中)。

In Karma tests, there are a lot of global variables and functions, which JSHint complains about (it is integrated into my editor).

如何告诉JSHint忽略这个特定文件中的所有未定义变量?我希望 / * jshint undef:false * / 关闭这些警告,但事实并非如此。

How can I tell JSHint to ignore all undefined variables in this one specific file? I would expect /* jshint undef: false */ to turn off these warning, but it doesn't.

推荐答案

告诉JSHint关于全局变量的正确方法是使用 globals 指令。例如:

The correct way to tell JSHint about globals is to use the globals directive. For example:

/*globals globalFunction, anotherGlobal, oneMore */

当JSHint遇到任何列出的标识符时,这将阻止{a}未定义警告。

This will prevent "{a} is not defined" warnings when JSHint encounters any of the listed identifiers.

或者,如果你真的想忽略该文件中的所有未定义警告,并且你正在使用JSHint 1.0.0或更高版本,你可以简单地关闭该特定警告:

Alternatively, if you really want to ignore all "not defined" warnings in that file, and you're using JSHint 1.0.0 or above, you can simply turn off that specific warning:

/*jshint -W117 */

这篇关于如何告诉JSHint忽略一个文件中的所有未定义变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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