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);