javascript 如何禁用警告“定义”未使用 JSHint 和 RequireJS 定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16260779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable the warning 'define' is not defined using JSHint and RequireJS
提问by Fizer Khan
I uses RequireJS AMD in my project. When i run jshint on my project, it throws error like
我在我的项目中使用 RequireJS AMD。当我在我的项目上运行 jshint 时,它会抛出类似的错误
In AMD Scripts
在 AMD 脚本中
'define' is not defined.
In Mocha test cases
在摩卡测试用例中
'describe' is not defined.
'it' is not defined.
How to remove this warning in jshint?
如何在 jshint 中删除此警告?
回答by bendytree
Just to expand a bit, here's a .jshintrc
setup for Mocha:
稍微扩展一下,这是.jshintrc
Mocha的设置:
{
....
"globals" : {
/* MOCHA */
"describe" : false,
"it" : false,
"before" : false,
"beforeEach" : false,
"after" : false,
"afterEach" : false
}
}
From the JSHint Docs- the false (the default) means the variable is read-only.
来自JSHint Docs- false(默认值)表示该变量是只读的。
If you are defining globals only for a specific file, you can do this:
如果您只为特定文件定义全局变量,您可以这样做:
/*global describe, it, before, beforeEach, after, afterEach */
回答by Grant Fong
jshint: {
options: {
mocha: true,
}
}
is what you want
是你想要的
回答by Roland Puntaier
回答by Shital Shah
Add this in your .jshintrc
将此添加到您的 .jshintrc
"predef" : ["define"] // Custom globals for requirejs
回答by Gilad Peleg
late to the party, but use this option in your jshintrc
:
聚会迟到,但在您的jshintrc
:
"dojo": true
and thou shall rest peacefully without red warnings...
你将安息,没有红色警告......
回答by salihcenap
If you are working on node js. Add these two lines in the beginning of your file
如果您正在处理节点 js。在文件的开头添加这两行
/*jslint node: true */
"use strict";
回答by Paul Grime
Read the docsand search for /*global
阅读文档并搜索/*global
回答by nyarasha
If you're trying to run JSHint in WebStorm with Mocha, as I am, go into:
如果您像我一样尝试在 WebStorm 中使用 Mocha 运行 JSHint,请进入:
WebStorm > Preferences > Languages & Frameworks > JavaScript > Code Quality Tools > JSHint
WebStorm > 首选项 > 语言和框架 > JavaScript > 代码质量工具 > JSHint
Scroll down to "Environments" and make sure you have selected the checkbox to enable "Mocha" which will set up the definitions for JSHint for Mocha for you.
向下滚动到“环境”并确保您已选中复选框以启用“Mocha”,这将为您设置 JSHint for Mocha 的定义。