prefer-queue-microtask
June 6, 2026 ยท View on GitHub
๐ Prefer queueMicrotask() over process.nextTick(), setImmediate(), and setTimeout(โฆ, 0).
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
queueMicrotask() is a portable way to queue a microtask in browsers and Node.js.
Prefer it over process.nextTick() for most userland code. The rule can also check setImmediate() and setTimeout(โฆ, 0) when enabled.
Examples
// โ
process.nextTick(callback);
// โ
queueMicrotask(callback);
// โ
process.nextTick(callback, value);
// โ
queueMicrotask(() => callback(value));
Only direct calls with one callback are autofixed. Calls with forwarded arguments are reported without a fix.
Options
Type: object
checkSetImmediate
Type: boolean
Default: false
Check setImmediate(callback).
Only calls whose timer handle is unused and whose callback is not obviously non-callable are checked. Used timer handles are ignored because queueMicrotask() cannot preserve them. Calls with extra arguments are reported without a fix.
/* eslint unicorn/prefer-queue-microtask: ["error", {"checkSetImmediate": true}] */
// โ
setImmediate(callback);
// โ
queueMicrotask(callback);
checkSetTimeout
Type: boolean
Default: false
Check setTimeout(callback, 0).
Only calls whose timer handle is unused and whose callback is not obviously non-callable are checked. Used timer handles are ignored because queueMicrotask() cannot preserve them. Calls with extra arguments or comments on the delay argument are reported without a fix.
/* eslint unicorn/prefer-queue-microtask: ["error", {"checkSetTimeout": true}] */
// โ
setTimeout(callback, 0);
// โ
queueMicrotask(callback);