javascript 语法抱怨 ES6 模块语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20160921/
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
syntastic complaining about ES6 module syntax
提问by dagda1
I love syntastic for javascript but I am using the new ES6 module tranpilerand syntastic is not happy about these type of statements:
我喜欢 JavaScript 的 Syntastic,但我使用的是新的ES6 模块 tranpiler,而 Syntastic 对这些类型的语句不满意:
import Typeahead from './lib/components/ember-typeahead';
Is there anyway that I can keep syntastic quiet about this type of statement?
无论如何,我可以对这种类型的语句保持句法安静吗?
回答by slindberg
Syntastic will use JSHint to check JavaScript syntaxif it's available(which I recommend over jslint).
Syntastic 将使用 JSHint 来检查 JavaScript 语法是否可用(我建议使用 jslint)。
JSHint supports es6 syntax with the esnext
flag, which includes support for the export
and import
module syntax.
JSHint 支持带有esnext
标志的es6 语法,其中包括对export
和import
模块语法的支持。
I suggest adding a .jshintrc
fileto your project to control JSHint's behavior (and thus Syntastic's) for your entire project:
我建议在你的项目中添加一个.jshintrc
文件来控制整个项目的 JSHint 的行为(以及 Syntastic 的行为):
{
"esnext": true
}
Note: be careful, since using the esnext
flag will add support for allof es6's new language sytaxthat JSHint currently supports, not just the module syntax.
注意:要小心,因为使用该esnext
标志将添加对JSHint当前支持的所有es6 新语言语法的支持,而不仅仅是模块语法。
Note: esnext
has now been deprecated in favour of the esversion
syntax.
注意:esnext
现在已被弃用,以支持esversion
语法。
{
"esversion": 6
}
回答by gnerkus
To work around this, I'd suggest the following steps as recommended here: Configure Vim for React:
要解决此问题,我建议按照此处的建议执行以下步骤:为 React 配置 Vim:
Install eslint
and babel-eslint
:
安装eslint
和babel-eslint
:
npm install -g eslint babel-eslint
Create a local .eslintrc
config in your project or a global ~/.eslintrc
configuration:
.eslintrc
在您的项目或全局~/.eslintrc
配置中创建本地配置:
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"settings": {
"ecmascript": 6
},
"rules": {
"strict": 0 // you can add more rules if you want
}
}
Finally, configure syntastic
to use eslint
:
最后,配置syntastic
使用eslint
:
let g:syntastic_javascript_checkers = ['eslint']