unicorn/no-new-buffer
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-new-buffer": "error",
},
},
];Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer().
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);Examples from the ESLint documentation.
unicorn/no-new-buffer
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-new-buffer": "error",
},
},
];unicorn/no-new-buffer
unicorn plugin · pedantic
{
"rules": {
"unicorn/no-new-buffer": "error"
}
}Biome does not have this rule.
Disallow instanceof with built-in objects
Enforce throwing TypeError in type checking conditions.
Require escape sequences to use uppercase or lowercase values.
Prefer consistent types when spreading a ternary in an array literal.
Prefer .includes() over .indexOf(), .lastIndexOf(), and Array#some() when checking for existence or non-existence.
Require new when creating an error.