javascript - eslint await Expected an assignment or function call and instead saw an expression - Stack Overflow

When I place this code for a promise that the result is not needed to proceed:await resultNotNeeded(bla

When I place this code for a promise that the result is not needed to proceed:

await resultNotNeeded(bla, foo);

I'm getting this eslint error:

[eslint] Expected an assignment or function call and instead saw an expression. (no-unused-expressions)

If the code is like this:

const dummy = await resultNotNeeded(bla, foo);

Then the eslint error is:

[eslint] 'dummy' is defined but never used (no-unused-vars)

Anyone knows how this should be fixed (I know I could do // eslint-disable-line no-unused-expressionsbut I'm looking if there is a better syntax for this statement.

When I place this code for a promise that the result is not needed to proceed:

await resultNotNeeded(bla, foo);

I'm getting this eslint error:

[eslint] Expected an assignment or function call and instead saw an expression. (no-unused-expressions)

If the code is like this:

const dummy = await resultNotNeeded(bla, foo);

Then the eslint error is:

[eslint] 'dummy' is defined but never used (no-unused-vars)

Anyone knows how this should be fixed (I know I could do // eslint-disable-line no-unused-expressionsbut I'm looking if there is a better syntax for this statement.

Share Improve this question edited Oct 3, 2016 at 14:50 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Oct 2, 2016 at 11:28 DavidDavid 2,7611 gold badge18 silver badges26 bronze badges 7
  • What if the async code fails? – thefourtheye Commented Oct 2, 2016 at 12:06
  • Well if you don't need the result, then it is an unused expression. Just disable the rule. – Bergi Commented Oct 2, 2016 at 12:57
  • 1 Admittedly, it's a bug in the rule. If they want to allow function calls for side effects, they should also allow await expressions. Please report it at eslints issue tracker. – Bergi Commented Oct 2, 2016 at 14:55
  • @thefourtheye, for that case, which I think is not the problem here, await is surrounded in a try {} catch {} block which I haven't written here to simplify and focus the question to the problem. @bergi, thanks, it was a problem that eslint was not updated – David Commented Oct 2, 2016 at 20:14
  • 1 "Does it mean that I can't use it in node with babel?" No, Babel allows you to use (future) features that are not natively supported yet. That's exactly what Babel enables you to do. "What are the implications?" Just that is not officially part of the language yet. "Will be a polyfill always needed?" Once the feature is officially part of the language, engines will natively support it (sonner or later). ES7 (ES2016) was released around June this year. async/await is currently a proposal scheduled for release next year: github./tc39/proposals/blob/master/finished-proposals.md – Felix Kling Commented Oct 3, 2016 at 17:54
 |  Show 2 more ments

1 Answer 1

Reset to default 5

This problem is fixed in [email protected].

The problem is that eslint was not updated in my system, I had [email protected]. Also npm was not up to date, so npm i eslint@latest -g was not updating eslint.

I had to install [email protected] (firstly I updated to [email protected] but it was not working, so I had to download source code from npm github and sudo make install) and then I could update [email protected].

Hope it helps!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418356a4626854.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信