no-buffer-constructor
Disallow the deprecated Buffer() constructor
deprecated
Buffer(value) does different things depending on the type of value. A string is copied, and a number allocates that many bytes. If value comes from a request, a caller who sends a number where you expect a string gets to decide how much memory your server allocates.
Node.js has deprecated the constructor. Buffer.from(), Buffer.alloc() and Buffer.allocUnsafe() each do one thing, and Buffer.from() throws if it gets a number.
ESLint has deprecated this rule. Its replacement, n/no-deprecated-api from eslint-plugin-n, isn't built into bun lint.
Examples#
example.js2 problems
const header = new Buffer(16)new Buffer() is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.;
const name = Buffer("Ada", "utf8")Buffer() is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.;example.jsNo problems
const header = Buffer.alloc(16);
const name = Buffer.from("Ada", "utf8");