Skip to content

bufferAllocators

Prefer modern Buffer allocation methods over the deprecated Buffer constructor.

✅ This rule is included in the node logical preset.

The new Buffer() constructor has been deprecated since Node.js 4 due to security and usability concerns. Modern alternatives provide safer and more explicit ways to create buffers.

Use Buffer.from() for creating a Buffer from existing data (strings, arrays, or ArrayBuffers). Use Buffer.alloc() for creating a Buffer of a specific size with zero-filled memory.

const buffer = new Buffer("7468697320697320612074c3a97374", "hex");
const buffer = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const buffer = new Buffer(10);

This rule is not configurable.

If you are working with legacy code that specifically requires the old Buffer constructor (which is highly unlikely in modern codebases), you might choose not to enable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.