question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule: enforce async/await consistency

See original GitHub issue

Please describe what the rule should do:

  • Enforce that all functions marked as async are being awaited when called.
  • Enforce that all functons that are being awaited be marked as async.
  • Prohibit awaiting functions that are not returning promises.

What category of rule is this? (place an “X” next to just one item)

[ ] Enforces code style [x] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

<!-- put your code examples here -->
function foo1(){  };
async function foo2(){ };
async function foo3(){ };

async function bar1(){
    const x = foo1(); // ok
    const y = foo2(); // error
}

async function bar2(){
    const x = await foo1(); // error
    const y = await foo2(); // ok
}

async function bar3(){
    Promise.all([foo2(), foo3()]); // error
}

async function bar4(){
    await Promise.all([foo2(), foo3()]); // ok
}

Why should this rule be included in ESLint (instead of a plugin)?

Because I think this is core to the language.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Jul 22, 2018

Thanks for your interest in improving ESLint. Unfortunately, it looks like this issue didn’t get consensus from the team, so I’m closing it. We define consensus as having three 👍s from team members, as well as a team member willing to champion the proposal. This is a high bar by design – we can’t realistically accept and maintain every feature request in the long term, so we only accept feature requests which are useful enough that there is a strong consensus among the team that they’re worth adding.

Since ESLint is pluggable and can load custom rules at runtime, the lack of consensus among the ESLint team doesn’t need to be a blocker for you using this in your project, if you’d find it useful. It just means that you would need to implement the rule yourself, rather than using a bundled rule that is packaged with ESLint.

2reactions
ljharbcommented, Feb 21, 2018

This is what a type system and/or tests are for; this just isn’t a lintable problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

return-await | typescript-eslint
Enforce consistent returning of awaited values.. Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.
Read more >
Async and Await in JavaScript, the extension to a promise.
Async / await allows us to write asynchronous code that reads like synchronous code. It allows for some nicer readability when working with...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis ... Enforce consistent brace style for...
Read more >
An extensible Syntax for effects like e.g. async-await - Pitches
I am open to any useful suggestions how to best implement the particular monad. My priority is to promote a consistent, extensible language ......
Read more >
Async/Await - Best Practices in Asynchronous Programming
Name, Description, Exceptions ; Avoid async void, Prefer async Task methods over async void methods, Event handlers ; Async all the way, Don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found