neuroanatomy / eslint-config-naat

Style rules for js code at NAAT
0 stars 2 forks source link

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

Open ntraut opened 3 years ago

ntraut commented 3 years ago

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 commented 3 years ago

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

ntraut commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

I see now. Thank you :)