JSHint是否支持异步/等待? [英] Does JSHint support async/await?

查看:52
本文介绍了JSHint是否支持异步/等待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将JSHint用于JavaScript项目(带有Visual Studio Code).在这个项目中,我使用async/await,JSHint将其突出显示为错误.

I'm using JSHint for the JavaScript project (with the Visual Studio Code). And in this project I use async / await, which JSHint highlights as errors.

我尝试设置jshint,但似乎"esversion"的最大版本为6.

I tried to set up jshint, but the it seems like the maxim version of "esversion" is 6.

jshint支持异步/等待吗?如果可以,如何打开它?如果没有,是否有任何解决方法?

Does jshint support async/await yet? If it does, how to turn it on? And if not, are there any workarounds?

推荐答案

更新(2019年2月):从2.10.1版本开始支持异步/等待.只需将.jshintrc更新为使用"esversion": 9. (+信息:版本更改日志)

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)


更新(2018年7月):随着JsHint 2.10.0的发布,异步/等待将到达. + info: https://github.com/jshint/jshint/pull/3273

Update (july 2018) : Async/await will arrive with the release of JsHint 2.10.0. +info : https://github.com/jshint/jshint/pull/3273


JSHINT开发社区认为:


The JSHINT developing community considers that:

  • JSHINT应该首先支持所有ES6语法,然后再开始实施ES7功能.
  • 异步功能仅处于第1阶段,因此语法可能会发生很大变化
  • 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软件包,其中包含对/async 的实验支持,称为 JSHINT-ESNEXT .


JSHINT-ESNEXT (PACKAGE)

However, there is an unnoficial JSHINT package, wich contains experimental support for await/async, called JSHINT-ESNEXT.

作者@ marcominetti 使用了官方的JSHint 2.7 Master分支,并介绍了该ES7功能,该功能取自 Seb Vincent esnextnext 分支.

The author, @marcominetti, used the official JSHint 2.7 Master branch and introduced this ES7 feature, taken from the Seb Vincent esnextnext branch.

检查 Npm软件包

安装:$ npm install -g jshint-esnext

Installation: $npm install -g jshint-esnext

现在(2017年7月),这是在JSHINT中支持等待/异步的唯一可行的方法.

Right now (Jul 2017) this is the only decent available approach to support await/async in JSHINT.

一种常见的建议解决方法或缓解措施是使用JSHINT ignore指令.

A common suggested workaround or mitigation practice, is using the JSHINT ignore directives.

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */

或者:

ignoreThis(); // jshint ignore:line

当我们的代码中包含大量异步/等待引用时,我个人认为这种缓解措施很肮脏且令人困惑.但是更令人困惑和肮脏的是JSHINT警告和错误;)

I personally find this mitigation practice, dirty and confusing, when our code has a big amount of async/await references. But more confusing and dirty are the JSHINT warnings and errors ;)

这篇关于JSHint是否支持异步/等待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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