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

research: configure eslint to prefer return next() when no await is needed #53

Closed
gao-sun opened this issue Jul 30, 2021 · 6 comments
Closed
Assignees
Labels

Comments

@gao-sun
Copy link
Member

gao-sun commented Jul 30, 2021

No description provided.

@gao-sun gao-sun self-assigned this Jul 30, 2021
@wangsijie
Copy link
Contributor

Koa's middleware uses ctx instead of return value, is not "pure function", so return value may not be important.

@gao-sun
Copy link
Member Author

gao-sun commented Jul 30, 2021

yes, just wanna align our code style.

@gao-sun
Copy link
Member Author

gao-sun commented Jul 30, 2021

agreed with you that return value doesn't matter.

@wangsijie
Copy link
Contributor

disallow return has an adventage: prevent treating the return value as useful staff by mistake

@gao-sun
Copy link
Member Author

gao-sun commented Jul 30, 2021

agreed, so i added the following type in packages/core/src/include.d/koa.d.ts:

export type KoaMiddleware<T, R> = (context: T, next: KoaNext<R>) => Promise<void>;

this makes sure that middleware is a void promise which means nothing. plus, return can enable eslint check for unreachable code and save 1 LOC for every middleware that doesn't need operations after next.

also check out the official example of using return next().

@gao-sun
Copy link
Member Author

gao-sun commented Aug 18, 2021

@gao-sun gao-sun closed this as completed Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants