eslint-plugin-parentheses-around-await
Version:
The ESLint plugin to ensure you don't try to use properties on a not-yet-awaited values.
37 lines (28 loc) • 762 B
Markdown
This plugin helps you to avoid a common mistake when using `async/await`: trying to access properties on an awaited value without wrapping it with parenthesis.
```javascript
const method = async () => ({
id: 25
});
const wrongId = await createModel().id; // wrongId === undefined
const correctId = (await createModel()).id; // correctId === 25
```
```bash
npm install eslint-plugin-parentheses-around-await
yarn add eslint-plugin-parentheses-around-await
```
`.eslintrc.js`:
```javascript
module.exports = {
"plugins": [
"eslint-plugin-parentheses-around-await"
],
"rules": {
"parentheses-around-await": 1 // 2 - error, 1 - warn, 0 - off.
}
};
```