Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add async modifier to containing function" inserts it multiple times when using an arrow function #237075

Open
StyleShit opened this issue Dec 29, 2024 · 2 comments
Assignees

Comments

@StyleShit
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.96.2
  • OS Version: Mac OS Sonoma 14.4

Steps to Reproduce:

  1. Use this code sinppet:
const a = () => {
  await b();
  await b();
};

async function b() {}
  1. Run the auto-fix on save.

  2. You'll end up with this invalid code (multiple asyncs):

const a = async async () => {
  await b();
  await b();
};

async function b() {}

I tried fixing it with ts-fix and it seems to work fine and add only a single async keyword.

Using the function keyword, however, works fine:

// original
function a() {
  await b();
  await b();
};

async function b() {}
// auto-fixed
async function a() {
  await b();
  await b();
}

async function b() {}

When cmd+zing, I get an invalid code that contains 2 async keywords, which probably means that it's being fixed in 2 passes?

@Muhammad-Noraeii
Copy link

This issue seems to occur due to a bug in VS Code's auto-fix mechanism, possibly caused by a two-pass fix or conflict with ESLint/Prettier.

Workarounds:

  1. Disable Auto-Fix on Save:
    "editor.codeActionsOnSave": null
  2. Run ESLint Fix Manually:
    eslint --fix <filename>
  3. Use Function Declarations instead of arrow functions.

Permanent Fix:

  1. Update VS Code and extensions (e.g., ESLint, Prettier).
  2. Check ESLint/Prettier configurations for conflicts.

@StyleShit
Copy link
Author

It happens to me even when all extensions are disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants