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

📎 Implement nursery/noFloatingPromises - typescript-eslint/no-floating-promises #4956

Open
2 of 6 tasks
kaykdm opened this issue Jan 24, 2025 · 1 comment
Open
2 of 6 tasks
Assignees
Labels
A-Analyzer Area: analyzer S-Feature Status: new feature to implement

Comments

@kaykdm
Copy link
Contributor

kaykdm commented Jan 24, 2025

Description

The rule will cover no-floating-promises

Some context here

Feature support / tasks checklist

  • support regular async functions
async function returnsPromiseFunction() {
    return 'value';
}
returnsPromiseFunction();
  • assigned functions
const returnsPromiseAssignedArrowFunction = async (): Promise<string> => {
  return 'value'; 
}
returnsPromiseArrowFunction();

const returnsPromiseAssignedFunction = async function (): Promise<string> {
  return 'value'; 
}
returnsPromiseAssignedFunction();
  • Promise
Promise.all([]);
Promise.reject('value').catch();

const promise = new Promise((resolve, reject) => resolve('value'));  
promise;
  • Class methods
class Api {
    async returnsPromise(): Promise<string> {
        return 'value';
    }

    async someMethod() {
        this.returnsPromise();
    }
}

const api = new Api();
api.returnsPromise();
  • Object method
const obj = {
    async returnsPromise() {
        return 'value';
    }
};
obj.returnsPromise();
  • Multi-file analysis - after this is implemented
@arendjr
Copy link
Contributor

arendjr commented Jan 24, 2025

Other important bullet points to add would be “inferred types” and “derived types”.

The first refers to working with functions that don’t have an explicit return type annotation, and are contextual inference. After you support assigned functions and promises, you’re already partly there, but you also need to consider control flow within a function to determine the possible return values.

Derived types are where the TypeScript type system gets really funky, and you need to support all the generics handling and other way to create types from types. There’s a lot of libraries that do stuff like that, and if you invoke methods on such types we’d also like to detect if they return a promise.

Both can get quite complex, but I expect I may start work on those sooner rather than later. I think we can coordinate by adding subtasks to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Analyzer Area: analyzer S-Feature Status: new feature to implement
Projects
None yet
Development

No branches or pull requests

3 participants