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.
Examples
Section titled “Examples”const buffer = new Buffer("7468697320697320612074c3a97374", "hex");
const buffer = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const buffer = new Buffer(10);const buffer = Buffer.from("7468697320697320612074c3a97374", "hex");
const buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const buffer = Buffer.alloc(10);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/no-new-buffer - Oxlint:
unicorn/no-new-buffer
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.