Skip to content
← Back to rules

unicorn/no-new-buffer Pedantic

💡 A suggestion is available for this rule.

What it does ​

Disallows the deprecated new Buffer() constructor.

Why is this bad? ​

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

Examples ​

Examples of incorrect code for this rule:

javascript
const buffer = new Buffer(10);

Examples of correct code for this rule:

javascript
const buffer = Buffer.alloc(10);

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-new-buffer": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-new-buffer": "error",
  },
});
bash
oxlint --deny unicorn/no-new-buffer

Version ​

This rule was added in v0.0.16.

References ​