JSHint 是否支持 async/await?
Does JSHint support async/await?
我正在为 JavaScript 项目(使用 Visual Studio 代码)使用 JSHint。在这个项目中,我使用了 async / await,JSHint 将其突出显示为错误。
我尝试设置 jshint,但 "esversion" 的最大版本似乎是 6。
jshint 支持 async/await 了吗?如果可以,如何开启?如果没有,是否有任何解决方法?
Does jshint support async/await yet?
不,截至 2017 年初还没有。
好像还不支持async/await
。从事 jsHint 工作的人们决定不支持 async/await
直到标准处于后期阶段(显然之前因为过早地支持还在变化的东西而被烧毁)——尽管实现已经存在(Babel、nodejs 等)。 ..).
如果您关注此 jsHint open issue thread,截至 7 天和 11 天前的最新评论,它仍然是一个未解决的问题。
And if not, are there any workarounds?
截至 2017 年 7 月,似乎有一个名为 jshint-esnext 的 jsHint 代码的分支在此处支持 async/await:https://www.npmjs.com/package/jshint-esnext.
OP 询问是否有任何解决方法。这是一个混乱,但我已经用 'async /**/' 和 'await /**/' 替换了我所有的 'async' 或 'await'。然后一个快速脚本将它们交换成 '/*async*/' 和 '/*await*/' 允许我用 jshint 检查。
它不漂亮,但它喂了斗牛犬。
Update (February 2019) : Async/await are now supported as of version 2.10.1. Simply update your .jshintrc to use "esversion": 9
. (+Info : Version changelog)
Update (july 2018) : Async/await will arrive with the release of JsHint 2.10.0. +info : https://github.com/jshint/jshint/pull/3273
JSHINT 开发社区认为:
- JSHINT should first support all the ES6 syntax before start implementing ES7 features.
- Async Functions are only at stage 1, so the syntax can change a lot
JSHINT-ESNEXT(包)
但是,有一个 非官方的 JSHINT 包,其中包含对 await/async 的 实验性支持,称为 JSHINT-ESNEXT.
作者,@marcominetti, used the official JSHint 2.7 Master branch and introduced this ES7 feature, taken from the Seb Vincent esnextnext分支。
勾选Npm Package, and the source in github
Installation: $npm install -g jshint-esnext
目前(2017 年 7 月)这是在 JSHINT 中支持 await/async 的唯一可用方法。
JSHINT 忽略(指令)
一个常见的建议解决方法或缓解措施是使用 JSHINT 忽略指令。
// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
或:
ignoreThis(); // jshint ignore:line
当我们的代码有大量 async/await 引用时,我个人认为这种缓解措施既肮脏又令人困惑。但更令人困惑和肮脏的是 JSHINT 警告和错误 ;)
注意:使用 "accepted answer" 中建议的分支 JSHINT-ESNEXT 包 (NPM, and github) 需要包含要设置的 "experimental" 选项。
/* experimental: [asyncawait] */
或
/* experimental: [asyncawait, asyncreqawait] */
查看源代码here了解详情。
我正在为 JavaScript 项目(使用 Visual Studio 代码)使用 JSHint。在这个项目中,我使用了 async / await,JSHint 将其突出显示为错误。
我尝试设置 jshint,但 "esversion" 的最大版本似乎是 6。
jshint 支持 async/await 了吗?如果可以,如何开启?如果没有,是否有任何解决方法?
Does jshint support async/await yet?
不,截至 2017 年初还没有。
好像还不支持async/await
。从事 jsHint 工作的人们决定不支持 async/await
直到标准处于后期阶段(显然之前因为过早地支持还在变化的东西而被烧毁)——尽管实现已经存在(Babel、nodejs 等)。 ..).
如果您关注此 jsHint open issue thread,截至 7 天和 11 天前的最新评论,它仍然是一个未解决的问题。
And if not, are there any workarounds?
截至 2017 年 7 月,似乎有一个名为 jshint-esnext 的 jsHint 代码的分支在此处支持 async/await:https://www.npmjs.com/package/jshint-esnext.
OP 询问是否有任何解决方法。这是一个混乱,但我已经用 'async /**/' 和 'await /**/' 替换了我所有的 'async' 或 'await'。然后一个快速脚本将它们交换成 '/*async*/' 和 '/*await*/' 允许我用 jshint 检查。
它不漂亮,但它喂了斗牛犬。
Update (February 2019) : Async/await are now supported as of version 2.10.1. Simply update your .jshintrc to use
"esversion": 9
. (+Info : Version changelog)
Update (july 2018) : Async/await will arrive with the release of JsHint 2.10.0. +info : https://github.com/jshint/jshint/pull/3273
JSHINT 开发社区认为:
- JSHINT should first support all the ES6 syntax before start implementing ES7 features.
- Async Functions are only at stage 1, so the syntax can change a lot
JSHINT-ESNEXT(包)
但是,有一个 非官方的 JSHINT 包,其中包含对 await/async 的 实验性支持,称为 JSHINT-ESNEXT.
作者,@marcominetti, used the official JSHint 2.7 Master branch and introduced this ES7 feature, taken from the Seb Vincent esnextnext分支。
勾选Npm Package, and the source in github
Installation: $npm install -g jshint-esnext
目前(2017 年 7 月)这是在 JSHINT 中支持 await/async 的唯一可用方法。
JSHINT 忽略(指令)
一个常见的建议解决方法或缓解措施是使用 JSHINT 忽略指令。
// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
或:
ignoreThis(); // jshint ignore:line
当我们的代码有大量 async/await 引用时,我个人认为这种缓解措施既肮脏又令人困惑。但更令人困惑和肮脏的是 JSHINT 警告和错误 ;)
注意:使用 "accepted answer" 中建议的分支 JSHINT-ESNEXT 包 (NPM, and github) 需要包含要设置的 "experimental" 选项。
/* experimental: [asyncawait] */
或
/* experimental: [asyncawait, asyncreqawait] */
查看源代码here了解详情。