简体   繁体   中英

node prevent accidentally calling async function without await

Is there a node or vscode feature that will keep me from accidentally forgetting to call my async functions with await? I've done this a few times and it always costs me hours of bug-hunting.

There is an ESlint rule which warns for async functions which have no await expression.

EDIT: You need to create '.eslintrc.json' file and add some rules to it. If you installed ESLint globally, you ca do it by running eslint --init . You can find more information in the vscode plugin github repo .

The availabe rules related to async/await are:

  • no-await-in-loop - disallow await inside of loops
  • no-return-await - disallow unnecessary return await
  • require-await - disallow async functions which have no await expression

You can find more about ESLint and available rules on the official documentation page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM