Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 824 Bytes

no-new-buffer.md

File metadata and controls

27 lines (18 loc) · 824 Bytes

Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer()

Enforces the use of Buffer.from and Buffer.alloc() instead of new Buffer(), which has been deprecated since Node.js 4.

Fail

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

Pass

const buf = Buffer.from('7468697320697320612074c3a97374', 'hex');
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
const buf = Buffer.alloc(10);