Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [return-await] allows function without return #8651

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

Closed
4 tasks done
devuxer opened this issue Mar 12, 2024 · 5 comments
Closed
4 tasks done

Bug: [return-await] allows function without return #8651

devuxer opened this issue Mar 12, 2024 · 5 comments
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@devuxer
Copy link

devuxer commented Mar 12, 2024

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.4.2&fileType=.tsx&code=PTAEDkHtQUwJzpOpIGNUFc4GdQDMlQAXACwEtsAaWADwAcZUiYATUAQwDtYEkAuALAAoGPSREO2AJ6dU%2BDLKJlI3InCkAVdQEEA5uzKcAFAEpQAb2GgOAdwMSACogC2FGADo4MbJAA2ANxhTAG5QEFBsEkgMXzYAIxgObnhEZC42PDIaYmgvIixudjsyRxc3T28-QKMAIn92XwwYGpNhAF8gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaaRAF1ml0IEMB3agS1PSnwDM3IAacbGRAI6wGJGvSYtI7Tj2xQAAqQCeABxQBjaAxWlCKeA1ykA9CSEjEYxswyRE0aPmjdeORao1ade5AaOmyCio6axYAbVc%2Be0dnWTkoanh6JVRIgF1eAF8QTKA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

// No error occurs for this, expected an error:
export async function tryTryAgain() {
    await Promise.resolve(); // should be an error and fix to return await Promise.resolve("value")
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
     "no-return-await": "off",
     "require-await": "off",
     "@typescript-eslint/require-await": "error",
     "@typescript-eslint/return-await": ["error", "always"],
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

Expected an error

Actual Result

No error, no autofix to return await

Additional Info

I do get an error and fix if I put only return Promise.resolve("value").

@devuxer devuxer added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 12, 2024
@Josh-Cena
Copy link
Member

This rule allows/disallows returned promises to be awaited. It doesn't say anything about non-returned promises. Why would you want this code to be flagged, anyway?

@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Mar 12, 2024
@bradzacher
Copy link
Member

Josh is correct - this rule doesn't enforce a promise is returned only that a returned promise is or isn't awaited. Closing as working as intended.

Feel free to continue discussing though and we can reopen if required.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Mar 12, 2024
@devuxer
Copy link
Author

devuxer commented Mar 12, 2024

@bradzacher,

Fair enough that I misinterpreted what this rule was supposed to do, but I keep reading and re-reading the documentation, and I'm not convinced it actually says what this rule does.

What is says it does:

Enforce consistent returning of awaited values.

What it actually does:

Enforce consistent awaiting of returned values.

Wordier but more complete version:

Enforce whether a returned promise is always awaited, never awaited, or awaited when inside a try/catch.

The reason I thought I wanted it to actually return the awaited value is to enable better stack traces, but I acknowledge I don't quite get the exact circumstances under which it's necessary to return the awaited expression to attain that benefit. It would be nice if the documentation made the stack trace behavior for the different options of this rule crystal clear, as it's difficult to really make an intelligent decision about this rule's options without this knowledge.

For what it's worth, my codebase currently uses return await for getters/queries and just await for setters/mutations.

@bradzacher
Copy link
Member

The wording in the docs is a bit cumbersome - happy to accept a PR if you think you can improve the docs.

@devuxer
Copy link
Author

devuxer commented Mar 12, 2024

@bradzacher, my previous comment is a pretty good preview of how I think the docs could be improved. I'm happy to work on a pull request, but I would appreciate some feedback on the two different wording options I offered as well as some help with my question about stack trace behavior

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

3 participants