[英]JSHint globals option is not working in .jshintrc
I'm using Brackets 1.2 and the extension brackets-jshint . 我正在使用Brackets 1.2和扩展括号-jshint 。 Here is my
.jshintrc
in my project root: 这是我的项目根目录中的
.jshintrc
:
{
'bitwise': true,
'boss': true,
'camelcase': true,
'curly': true,
'devel': true,
'eqeqeq': true,
'eqnull': true,
'expr': true,
'forin': true,
'iterator': false,
'latedef': true,
'multistr': false,
'nocomma': true,
'noarg': true,
'noempty': true,
'nonbsp': true,
'nonew': true,
'quotmark': 'single',
'undef': true,
'unused': true,
'globals': {
'$': true,
'document': true,
'jQuery': true,
'window': true
}
}
The globals
option is not working and the white list of global variables are still being warned by JSHint. globals
选项不起作用,JSHint仍在警告全局变量的白名单。
I also tried these: 我也试过这些:
globals: true
jquery: true
devel: true
But no success, $
, jquery
, window
, document
and alert
are still warned. 但是没有成功,
$
, jquery
, window
, document
和alert
仍然被警告。
You must replace single quotes with double in .jshintrc
: ) This answer is to short, so I'm going to add a little explanations … 你必须用
.jshintrc
double替换单引号.jshintrc
这个答案是简短的,所以我将添加一些解释......
Just open Debug » Developers tools try to validate some JavaScript file – you can see in debug console 只需打开Debug»Developers工具尝试验证一些JavaScript文件 - 您可以在调试控制台中看到
JSHint: error parsing /project/path/.jshintrc.
JSHint:解析/project/path/.jshintrc时出错。 Details: SyntaxError: Unexpected token '
详细信息:SyntaxError:意外的令牌'
As method responsible for reading .jshintrc looks like: 作为负责阅读的方法.jshintrc看起来像:
try {
config = JSON.parse(removeComments(content));
} catch (e) {
console.error("JSHint: error parsing " + file.fullPath + ". Details: " + e);
result.reject(e);
return;
}
JSON.parse implements http://www.ietf.org/rfc/rfc4627.txt - according to ECMAScript Specification and there is no place for '
. JSON.parse实现http://www.ietf.org/rfc/rfc4627.txt - 根据ECMAScript规范 ,没有
'
。
From rfc 4627 only valid structure to describe JSON is 从rfc 4627开始,只有有效的结构才能描述JSON
string = quotation-mark *char quotation-mark char = unescaped / escape ( %x22 / ; " quotation mark U+0022 %x5C / ; \\ reverse solidus U+005C %x2F / ; / solidus U+002F %x62 / ; b backspace U+0008 %x66 / ; f form feed U+000C %x6E / ; n line feed U+000A %x72 / ; r carriage return U+000D %x74 / ; t tab U+0009 %x75 4HEXDIG ) ; uXXXX U+XXXX escape = %x5C ; \\ quotation-mark = %x22 ; "
Please make sure you have disabled JSLint, the linter that comes with Brackets by default. 请确保您已禁用JSLint,默认情况下附带Brackets的linter。 You can do so by adding this snippet to your brackets.json (open via
Debug > Show Preferences File
): 您可以通过将此片段添加到bracket.json(通过
Debug > Show Preferences File
打开)来实现:
"language": {
"javascript": {
"linting.prefer": "JSHint",
"linting.usePreferredOnly": true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.