Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Drop redundant return await on a returned promise
Choose direct promise return or return await according to error handling, cleanup and stack-trace needs; do not remove await based on an assumed extra microtask.
Bad example
| 1 | async function read() { |
| 2 | try { |
| 3 | return fetchData(); |
| 4 | } catch (error) { |
| 5 | return fallback(error); |
| 6 | } |
| 7 | } |
Explanation (EN)
The returned promise can reject after the function leaves the try block, so the local catch does not handle that rejection.
Objašnjenje (HR)
Good example
| 1 | async function read() { |
| 2 | try { |
| 3 | return await fetchData(); |
| 4 | } catch (error) { |
| 5 | return fallback(error); |
| 6 | } |
| 7 | } |
Explanation (EN)
Awaiting the promise allows the local catch to handle its asynchronous rejection.
Objašnjenje (HR)
Notes (EN)
For an async function that directly forwards a promise, inspect surrounding try/catch/finally and diagnostic requirements before simplifying it. A catch must await the rejection to handle it locally.
Exceptions / Tradeoffs (EN)
Keep return await when local error handling, asynchronous cleanup ordering or useful stack traces depend on awaiting. Modern engines do not incur the historical extra-microtask cost for return await.