{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/4337","labels_url":"https://api.github.com/repos/eslint/eslint/issues/4337/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/4337/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/4337/events","html_url":"https://github.com/eslint/eslint/issues/4337","id":115272364,"number":4337,"title":"Catch issue when apply ! on promise rather than value when using async and await","user":{"login":"timnew","id":1287238,"avatar_url":"https://avatars.githubusercontent.com/u/1287238?v=3","gravatar_id":"","url":"https://api.github.com/users/timnew","html_url":"https://github.com/timnew","followers_url":"https://api.github.com/users/timnew/followers","following_url":"https://api.github.com/users/timnew/following{/other_user}","gists_url":"https://api.github.com/users/timnew/gists{/gist_id}","starred_url":"https://api.github.com/users/timnew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timnew/subscriptions","organizations_url":"https://api.github.com/users/timnew/orgs","repos_url":"https://api.github.com/users/timnew/repos","events_url":"https://api.github.com/users/timnew/events{/privacy}","received_events_url":"https://api.github.com/users/timnew/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-05T12:21:06Z","updated_at":"2015-11-05T12:38:56Z","closed_at":null,"body":"**When does this rule warn? Please describe and show example code:**\r\n\r\nTo invert the boolean value returned from promise with `await`, we should put the `!` before the `await` keyword. But this is counterintuitive and error-prone.\r\n\r\ne.g.\r\n```js\r\nfunction returnFalse() {\r\n  return Promise.resolve(false);\r\n}\r\n\r\nasync function test() {\r\n  if(await !returnFalse()) {\r\n    console.log('ok');\r\n  }  \r\n}\r\n\r\ntest();\r\n```\r\n\r\nWe might expect `ok` to be displayed, but it never does. Since we apply `!` on the `promise` return by async function, which is meaningless in most cases. So it would be nice if any code that apply `!` after `await` rather than before.\r\n\r\nHere is the correct `test()`:\r\n```js\r\nasync function test() {\r\n  if(! await returnFalse()) {\r\n    console.log('ok');\r\n  }  \r\n}\r\n\r\n```\r\n\r\n**Is this rule preventing an error or is it stylistic?**\r\n\r\nYes it preventing error.\r\n\r\n**Why is this rule a candidate for inclusion instead of creating a custom rule?**\r\n\r\nI think it will be a general issue when writing code with `async/await`. And it is kind of hard to find if you haven't aware it clearly.\r\n\r\n**Are you willing to create the rule yourself?**\r\n\r\nI think I can have a try\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/27993346-catch-issue-when-apply-on-promise-rather-than-value-when-using-async-and-await?utm_campaign=plugin&utm_content=tracker%2F282608&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F282608&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/154047680","html_url":"https://github.com/eslint/eslint/issues/4337#issuecomment-154047680","issue_url":"https://api.github.com/repos/eslint/eslint/issues/4337","id":154047680,"user":{"login":"timnew","id":1287238,"avatar_url":"https://avatars.githubusercontent.com/u/1287238?v=3","gravatar_id":"","url":"https://api.github.com/users/timnew","html_url":"https://github.com/timnew","followers_url":"https://api.github.com/users/timnew/followers","following_url":"https://api.github.com/users/timnew/following{/other_user}","gists_url":"https://api.github.com/users/timnew/gists{/gist_id}","starred_url":"https://api.github.com/users/timnew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timnew/subscriptions","organizations_url":"https://api.github.com/users/timnew/orgs","repos_url":"https://api.github.com/users/timnew/repos","events_url":"https://api.github.com/users/timnew/events{/privacy}","received_events_url":"https://api.github.com/users/timnew/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T12:38:56Z","updated_at":"2015-11-05T12:38:56Z","body":"This case should apply to all urinary operators, including `!`, `~`, and `-`."}}