49

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?

MDMower
  • 808
  • 8
  • 27
Alena Gilevskaya
  • 535
  • 1
  • 4
  • 8

4 Answers4

55

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

colxi
  • 7,640
  • 2
  • 45
  • 43
  • 1
    Thanks Colix, this helped. But what about now (Apr, 2018)? Is Async supported in jshint? – antew Apr 15 '18 at 14:33
  • How do you actually use jshint-esnext? Once it's installed, should you be able to use it like `jshint-esnext myscript.js`? Cause that's not working for me. – Jack M May 31 '18 at 15:00
  • 1
    To use last features of JS I recommend to use eslint instead of jshint. – Thomas Champion Jun 12 '18 at 13:44
  • If you get this error: "Incompatible values for the 'esversion' and 'esnext' linting options" Its due to esnext being deprecated. So remove esnext from your jshint file, and you'll be good. Source: https://github.com/Microsoft/vscode-jshint/issues/49 – Logan Cundiff Sep 01 '21 at 16:05
14

Does jshint support async/await yet?

No, not yet as of early 2017.

It appears that it does not yet support async/await. Folks working on jsHint have decided not to support async/await until standards were in a late stage (having apparently been burned previously by supporting things too early when they were still changing) - though implementations already exist (Babel, nodejs, etc...).

If you follow this jsHint open issue thread, it is still an open issue as of recent comments 7 and 11 days ago.

And if not, are there any workarounds?

As of July 2017, there appears to be a fork of the jsHint code called jshint-esnext that has support for async/await here: https://www.npmjs.com/package/jshint-esnext.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
4

Note: Using the forked JSHINT-ESNEXT package (NPM, and github) as suggested in the "accepted answer" requires the inclusion of the "experimental" option to be set.

/* experimental: [asyncawait] */

or

/* experimental: [asyncawait, asyncreqawait] */

See the source code here for details.

JoelABair
  • 116
  • 2
  • 3
2

The OP asked it there were any workarounds. It's a kludge, but I've replaced all my 'async' or 'await' with 'async /**/' and 'await /**/'. Then a quick script to swap them into '/*async*/' and '/*await*/' allows me to check with jshint.

It's not pretty, but it feeds the bulldog.

JohnN
  • 21
  • 1