3

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
David
  • 2,741
  • 16
  • 26
  • What if the async code fails? – thefourtheye Oct 02 '16 at 12:06
  • Well if you don't need the result, then it *is* an unused expression. Just disable the rule. – Bergi Oct 02 '16 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 Oct 02 '16 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 Oct 02 '16 at 20:14
  • `async/await` is not part of ES7. – Felix Kling Oct 03 '16 at 14:50
  • @FelixKling I'm a little confused and tried to search around the web but there is a lot of buzz. Does it mean that I can't use it in node with babel? What are the implications? Will be a polyfill always needed? – David Oct 03 '16 at 17:48
  • 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: https://github.com/tc39/proposals/blob/master/finished-proposals.md – Felix Kling Oct 03 '16 at 17:54

1 Answers1

5

This problem is fixed in eslint@3.6.0.

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

I had to install npm@3.10.7 (firstly I updated to npm@3.10.8 but it was not working, so I had to download source code from npm github and sudo make install) and then I could update eslint@3.7.0.

Hope it helps!

David
  • 2,741
  • 16
  • 26