Skip to content

[no-floating-promises] Rule proposal: Add ignore for typescript types or specific methods #4791

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
SimonSimCity opened this issue Apr 6, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@SimonSimCity
Copy link

Description

Some of the functions I have in my code do return a promise, where I'm fine having them "floating around". They usually are functions whose promise already is handled in a different way, and I don't want to add .catch(() => {}) to all of them.

One example I have at hand is the package @vue/apollo-composable which lets me run a query to a GraphQL server. This function returns properties (result, error, loading) which are objects which will get the value as they arrive (vue calls it reactive). The function refetch() now returns a promise which contains the result when it arrives, but I don't need it because the reactive properties will reflect the values.

My idea was now if it would be possible to ignore those calls but not all promises ... Maybe by type (Promise<ApolloQueryResult<TResult>>) or maybe by the name of the function returning the promise.

As you see, I myself am not yet that sure about how the extra feature to the rule no-floating-promises could be implemented, but am rather open to discuss it to find a good option. If you see it not being feasible, it would be nice to know a bit more about the implementation here, to wrap my head around what would be possible instead.

Fail

new Promise(() => { });

Pass

import * as VueApolloComposable from "@vue/apollo-composable";
import gql from "graphql-tag";

const query = VueApolloComposable.useQuery<Record<string, string>, Record<string, string>>(
  gql`
    query Test() {
  test() {
    result
  }
}`,
  {},
  {}
);

// Returns a promise which is already resolved by the query.result-property
query.refetch();
@SimonSimCity SimonSimCity added enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 6, 2022
@bradzacher
Copy link
Member

Duplicate of #4722

If you're using async/await you can just await the promise and that's it.

Otherwise use the void operator to signal you're intentionally floating the promise.

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look enhancement: new base rule extension New base rule extension required to handle a TS specific case labels Apr 6, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants