Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't await synchronous, non-Promise values
Avoid await on known synchronous values unless the scheduling boundary is intentional; it is not a semantic no-op.
Bad example
| 1 | async function dispatch(name: string): Promise<void> { |
| 2 | await runSynchronousJob(name); |
| 3 | } |
Explanation (EN)
A synchronous call does not need promise unwrapping, but await still yields continuation.
Objašnjenje (HR)
Sinkroni poziv ne treba razrješavanje promisea, ali await i dalje odgađa nastavak.
Good example
| 1 | async function dispatch(name: string): Promise<void> { |
| 2 | runSynchronousJob(name); |
| 3 | } |
Explanation (EN)
The public Promise<void> contract remains; only the unnecessary internal await is removed.
Objašnjenje (HR)
Javni ugovor Promise<void> ostaje sačuvan; uklonjen je samo nepotrebni unutarnji await.
Notes (EN)
Remove await on a known synchronous value when no intentional scheduling boundary is required; preserve the enclosing function's promised API.
Bilješke (HR)
Await nad poznatom sinkronom vrijednošću ukloni kada nije potrebna namjerna granica raspoređivanja. Sačuvaj obećani API okolne funkcije.
Exceptions / Tradeoffs (EN)
Awaiting T | Promise<T> or a thenable is valid. Even await on a plain value defers continuation, so removing it can change ordering; use an explicit scheduling contract if that yield is intentional.
Iznimke / Tradeoffi (HR)
Await nad T | Promise<T> ili thenable vrijednošću je valjan. Čak i za običnu vrijednost odgađa nastavak, pa uklanjanje može promijeniti redoslijed. Namjerno odgađanje treba imati jasan ugovor.