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

Bug: [return-await] "in-try-catch" not respected with explicit resource management #7889

Open
4 tasks done
andrew0 opened this issue Nov 7, 2023 · 0 comments · May be fixed by #9044
Open
4 tasks done

Bug: [return-await] "in-try-catch" not respected with explicit resource management #7889

andrew0 opened this issue Nov 7, 2023 · 0 comments · May be fixed by #9044
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@andrew0
Copy link

andrew0 commented Nov 7, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&fileType=.tsx&code=IYZwngdgxgBAZgV2gFwJYHsI1JKAxCACgEoYBvAKBmwHdhVkYIBTGmABQCd0BbVEZgB4AbulQATAHyFCnZiHQAbYc1IBeSTAHIAKqh7N0CZLPlKVAGhgBGAAy3ixANxUYUTAsXMAdIvQBzQgByHGgCGHFMZiDnVzlkBE4sIIUDZAALVAh-IJcAXwoKUNhEFAwseMSIAEE6BhJyVwQQLP8YAH0YNUbqagBtAGUwHgAjJW9xfgAHdAEAXQAuGAaNHt7qdwhPHz9AoMmQGYEYl3WC6gK45gSk2npGYoISfMLgOsZKpNr758LmAA8ZpxGGQYHkXEA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aRfWaJ2gQwDufSvnRRE0aAHtokcGAC%2BIBUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

async function asyncFn() {
  await new Promise<void>((resolve) => setTimeout(resolve, 50));
  return 'something';
}

async function returnAwait() {
  using _ = {
    [Symbol.dispose]: () => {
      console.log('dispose');
    }
  }

  return await asyncFn();
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/return-await": "error",
  },
};

tsconfig

{
  "compilerOptions": {
    "lib": ["esnext.disposable"]
  }
}

Expected Result

I expect that the line return await asyncFn(); does not trigger a linting error, since the using statement is effectively a try/catch/finally around the scope of the function.

Actual Result

return await asyncFn(); triggers a linting error for an unnecessary await, and it gets autofixed to return asyncFn();. This makes it so that the disposers run before the returned promise settles, when previously they would run after the returned promise settles.

Additional Info

Demonstrates difference in behavior after running eslint --fix: https://stackblitz.com/edit/node-fsxhhx?file=src%2Fwith-await.ts

@andrew0 andrew0 added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 7, 2023
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Nov 10, 2023
kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants