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.

Proposal: Implement autofix for `no-return-await`

See original GitHub issue

Versions

  • ESLint: 3.10
  • Node: 7.1
  • npm: 4.0.2

Description

I propose to implement an auto-fixer for the new no-return-await rule. Since return await value has the same meaning as return value in async functions, an auto-fix can be implemented which simply removes the await keyword.

There is currently one known exception to this - try/catch blocks. See pending issue #7581 (PR with fix also pending merge).


I have an implementation of the auto-fixer ready - if you are interested you may see it here. Once this issue gets accepted I will open a PR with the actual implementation for further review.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Nov 22, 2016

@isiahmeadows @not-an-aardvark This is interesting discussion, but can we please keep this issue focused to autofixing (or not) for no-return-await? Please feel free to visit our Gitter chat if you wish to continue the general auto-fix discussion, or please feel free to open an issue if you believe you have identified an issue with one of our other rules.

1reaction
dead-claudiacommented, Nov 22, 2016

Oh. I didn’t realize strict limited itself to that.

I’ll also point out that it’s generally a bad idea to rely on the resolution order of two independent promises, so I’d be shocked if they would actually break anything in practice. (The above sample already warns, and the autofixer doesn’t touch ignored lines IIUC).

If you actually wish for that kind of behavior, it’s best to make it explicit, though, so ESLint doesn’t complain.

// Option 1
const p = Promise.resolve();

async function foo() {
  // I know it seems odd, but it's intentional.
  return await p; // eslint-disable-line no-return-await
}

async function bar() {
  return p;
}

// Option 2
const p = Promise.resolve();

async function foo() {
  // Very obviously intentional.
  return Promise.resolve().then(() => p);
}

async function bar() {
  return p;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto-fix and format your JavaScript with ESLint - IBM Developer
Get the quick tips and tricks you need to use ESLint to autofix and format your JavaScript.
Read more >
eslint | Yarn - Package Manager
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and...
Read more >
ESLint v3.13.0 released
This is a summary of some of the notable changes in this version of ESLint. New Rules. One new rule was added: prefer-destructuring....
Read more >
demo-outil-edition - node_modules - eslint - CHANGELOG.md
73596cb Update: Add enforceForSwitchCase option to use-isnan (#12106) ... e85d27a Fix: no-regex-spaces false positives and invalid autofix ...
Read more >
Node.js API - ESLint - Breword 文档集合
The purpose of the Node.js API is to allow plugin and tool authors to use the ESLint functionality ... And here is an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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