{"record":{"id":"da1b16c5eac243b3","repo":"oxc-project/oxc","slug":"use-buffer-alloc-or-buffer-from-instead-of","errorCode":null,"errorMessage":"Use `Buffer.alloc()` or `Buffer.from()` instead of the deprecated `new Buffer()` constructor.","messagePattern":"Use `Buffer\\.alloc\\(\\)` or `Buffer\\.from\\(\\)` instead of the deprecated `new Buffer\\(\\)` constructor\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_new_buffer.rs","lineNumber":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::IsGlobalReference;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_new_buffer_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `Buffer.alloc()` or `Buffer.from()` instead of the deprecated `new Buffer()` constructor.\")\n        .with_help(\"`new Buffer()` is deprecated, use `Buffer.alloc()` or `Buffer.from()` instead.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoNewBuffer;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows the deprecated `new Buffer()` constructor.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Enforces the use of [Buffer.from](https://nodejs.org/api/buffer.html#static-method-bufferfromarray) and [Buffer.alloc()](https://nodejs.org/api/buffer.html#static-method-bufferallocsize-fill-encoding) instead of [new Buffer()](https://nodejs.org/api/buffer.html#new-bufferarray), which has been deprecated since Node.js 4.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_new_buffer.rs#L1-L31","documentation":"Raised by unicorn/no-new-buffer when the deprecated Node.js `new Buffer()` constructor is invoked (detected as a global reference in run()). The constructor is unsafe because it can initialize from uninitialized memory; the faulting input is the `new Buffer(...)` expression at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_new_buffer.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use `Buffer.alloc(size, fill)` to allocate initialized memory","Use `Buffer.from(data)` to create a buffer from existing data"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}