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

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

问题描述

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

我尝试设置 jshint,但esversion"的格言版本似乎是 6.

jshint 支持 async/await 吗?如果可以,如何开启?如果没有,是否有任何解决方法?

解决方案

更新(2019 年 2 月):从 2.10.1 版开始,现在支持异步/等待.只需更新您的 .jshintrc 以使用 "esversion": 9.(+信息:版本变更日志)

<小时><块引用>

更新(2018 年 7 月):Async/await 将随着 JsHint 2.10.0 的发布而到来.+信息:https://github.com/jshint/jshint/pull/3273

<小时>

JSHINT 开发社区认为:

<块引用>
  • 在开始实现 ES7 特性之前,JSHINT 应该首先支持所有 ES6 语法.
  • 异步函数仅处于第 1 阶段,因此语法可能会发生很大变化

<小时>

JSHINT-ESNEXT(包)

但是,有一个非官方 JSHINT 包,其中包含对等待/异步的实验性支持,称为 JSHINT-ESNEXT.

作者@marcominetti,使用了官方的 JSHint 2.7 Master 分支并引入了这个 ES7 特性,取自Seb Vincent esnext 分支.

检查 Npm Packagegithub 中的源

<块引用>

安装:$npm install -g jshint-esnext

目前(2017 年 7 月)这是在 JSHINT 中支持 await/async 的唯一合适的可用方法.

<小时>

JSHINT 忽略(指令)

一个常见的建议解决方法或缓解做法,是使用 JSHINT 忽略指令.

//此处的代码将使用 JSHint 进行检查./* jshint 忽略:开始 *///这里的代码会被 JSHint 忽略./* jshint 忽略:结束 */

或者:

ignoreThis();//jshint 忽略:行

当我们的代码有大量 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.

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

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

解决方案

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


The JSHINT developing community considers that:

  • 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 (PACKAGE)

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

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

Check the Npm Package, and the source in github

Installation: $npm install -g jshint-esnext

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


JSHINT IGNORE (DIRECTIVE)

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 */

Or:

ignoreThis(); // jshint ignore:line

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天全站免登陆