Skip to main content

What it flags

A call such as fs.readFile(path, 'utf8', (err, text) => ...), dns.lookup(host, cb), crypto.randomBytes(16, cb) or zlib.gzip(data, cb) that passes an inline callback to a Node.js API with a promise form. The callee must resolve to the built-in module through an import, import * as, named import or require, so a project function with the same name is not reported. Covered members:
  • fs: access, appendFile, chmod, chown, copyFile, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, symlink, truncate, unlink, utimes, writeFile;
  • dns: lookup, resolve, resolve4, resolve6, resolveCname, resolveMx, resolveNs, resolveSrv, resolveTxt, reverse;
  • crypto: generateKeyPair, pbkdf2, randomBytes, scrypt;
  • zlib: brotliCompress, brotliDecompress, deflate, deflateRaw, gunzip, gzip, inflate, unzip.
It stays quiet for fs/promises and fs.promises, sync forms, calls whose result is kept, calls without an inline function as the last argument, callbacks that pass their error to the enclosing function’s own callback (such as a custom lookup hook for an http agent, which must keep the callback contract), fs.exists (reported by deprecated-node-api) and child_process.exec/execFile, whose callback is often used to read the output of a failed command.

How to review

Use node:fs/promises or node:dns/promises, or wrap a crypto or zlib function once with util.promisify, then await it inside try/catch:
Callers of a callback-style function must change too, so there is no automatic fix.

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: