Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

javascript - Does JSHint support async/await?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...