Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Only mark a function async when it actually awaits
Remove async without await only when the function does not need its promise-returning or rejection-normalizing contract.
Bad example
| 1 | const handler = async (req, res) => { |
| 2 | res.json(buildDocs()); |
| 3 | }; |
Explanation (EN)
An unnecessary async marker can hide a synchronous helper, but removing it is safe only when callers accept the resulting contract.
Objašnjenje (HR)
Good example
| 1 | const handler = (req, res) => { |
| 2 | res.json(buildDocs()); |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Before removing async from a function with no await, inspect its callback/API contract, synchronous throws and how callers consume the return value.
Exceptions / Tradeoffs (EN)
Keep async when the API must always return a promise or convert synchronous exceptions into rejections. Returning an existing promise without async can also change promise identity and error timing.