# no-new-buffer

Rule `unicorn/no-new-buffer`. Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`.

- Source: unicorn
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 12.8M weekly downloads of presets that enable it
- Trend: +40.7% last quarter
- Rank: #733 by reach, #942 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-new-buffer` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-new-buffer.md) |
| Oxlint | `unicorn/no-new-buffer` | no | safe | plugin `unicorn`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-new-buffer.html) |

## Code examples

### Incorrect: the rule reports this

```js
const buffer = new Buffer('7468697320697320612074c3a97374', 'hex');
```

```js
const buffer = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

```js
const buffer = new Buffer(10);
```

### Correct: the rule accepts this

```js
const buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
```

```js
const buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
```

```js
const buffer = Buffer.alloc(10);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-new-buffer": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/no-new-buffer": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Anthony Fu's config](https://lintradar.dev/presets/antfu.md) | ESLint | `@antfu/eslint-config` | 294 | 758.7K | +49.9% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-instanceof-builtins](https://lintradar.dev/rules/unicorn/no-instanceof-builtins.md): Disallow `instanceof` with built-in objects
- [unicorn/prefer-type-error](https://lintradar.dev/rules/unicorn/prefer-type-error.md): Enforce throwing `TypeError` in type checking conditions.
- [unicorn/escape-case](https://lintradar.dev/rules/unicorn/escape-case.md): Require escape sequences to use uppercase or lowercase values.
- [unicorn/consistent-empty-array-spread](https://lintradar.dev/rules/unicorn/consistent-empty-array-spread.md): Prefer consistent types when spreading a ternary in an array literal.
- [unicorn/prefer-includes](https://lintradar.dev/rules/unicorn/prefer-includes.md): Prefer `.includes()` over `.indexOf()`, `.lastIndexOf()`, and `Array#some()` when checking for existence or non-existence.
- [unicorn/throw-new-error](https://lintradar.dev/rules/unicorn/throw-new-error.md): Require `new` when creating an error.

---

Web page: https://lintradar.dev/rules/unicorn/no-new-buffer. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
