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

require-await and no-return-await rules are incompatible #3

Open
ntraut opened this issue May 24, 2021 · 5 comments
Open

require-await and no-return-await rules are incompatible #3

ntraut opened this issue May 24, 2021 · 5 comments

Comments

@ntraut
Copy link
Member

ntraut commented May 24, 2021

As pointed out in this issue if we have both require-await and no-return-await rules turned on, when the only call to an async function is on the return statement we get an error whatever we use await or not.
We should disable at least one these rules.

@r03ert0
Copy link
Member

r03ert0 commented Aug 29, 2021

so return await thing(); doesn't work, but what about await thing(); return?

@ntraut
Copy link
Member Author

ntraut commented Aug 31, 2021

so return await thing(); doesn't work, but what about await thing(); return?

It would prevent to do an async one line arrow function, but in this case why forbidding return await? According to the explanations of the rule (https://eslint.org/docs/rules/no-return-await), the goal is to avoid an unnecessary micro task but if we decompose we have it.

@r03ert0
Copy link
Member

r03ert0 commented Aug 31, 2021

something like const result = (arg) => await thing(arg)? I don't think you need the return there. But change the eslint config as you think it's better! :D

@ntraut
Copy link
Member Author

ntraut commented Sep 1, 2021

something like const result = (arg) => await thing(arg)? I don't think you need the return there. But change the eslint config as you think it's better! :D

In a one line arrow function the return is implicit and eslint considers there is one. Your syntax is not correct since you use await in a non async function, but const result = async (arg) => await thing(arg) will break the no-return-await rule and const result = async (arg) => thing(arg) will break the require-await rule. The only syntax which doesn't break any rule is const result = (arg) => thing(arg) but we no longer see that result is an async function.

@r03ert0
Copy link
Member

r03ert0 commented Sep 1, 2021

I see now. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants