{"record":{"id":"db84b74e80adef49","repo":"oxc-project/oxc","slug":"the-function-binding-is-unnecessary","errorCode":null,"errorMessage":"The function binding is unnecessary.","messagePattern":"The function binding is unnecessary\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_extra_bind.rs","lineNumber":15,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode, ast_util::is_method_call, context::LintContext, rule::Rule,\n    utils::function_body_contains_this,\n};\n\nfn no_extra_bind_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"The function binding is unnecessary.\")\n        .with_label(span)\n        .with_help(\"Remove the `.bind` call.\")\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoExtraBind;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unnecessary calls to `.bind()`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This rule is aimed at avoiding the unnecessary use of `bind()`\n    /// and as such will warn whenever an immediately-invoked function expression (IIFE) is using `bind()`\n    /// and doesn’t have an appropriate `this` value.\n    /// This rule won’t flag usage of `bind()` that includes function argument binding.","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_extra_bind.rs#L1-L33","documentation":"This diagnostic comes from the `no_extra_bind` rule in oxlint. It reports a `.bind(receiver)` call on a function that never uses `this`, so the bound receiver has no effect. The rule matches only bind calls with exactly one argument: a bind that also pre-fills function arguments is not flagged, because it still has an effect. Arrow functions are always flagged, since they have no `this` of their own.","triggerScenarios":"`const f = function () { return 1; }.bind(obj);` — the body has no `this`, so the receiver is dead. Also `const g = (() => { foo(); }).bind(this);` on an arrow, flagged because arrows ignore the receiver.","commonSituations":"Code is copied from a class-based example into a plain function. Defensive `.bind(this)` is sprinkled during a refactor away from classes. A callback is registered where the receiver was never needed.","solutions":["Remove the `.bind(...)` call.","Add the intended `this` reference to the body when the function should use the receiver.","Replace with an arrow closure when you only needed the binding for style.","Suppress once with `// oxlint-disable-next-line no-extra-bind`."],"exampleFix":"// before\nconst send = function (msg) {\n  return post(msg);\n}.bind(socket);\n\n// after\nconst send = (msg) => post(msg);","handlingStrategy":"validation","validationCode":"// list bind sites for manual review before lint\nfor (const m of src.matchAll(/\\.bind\\s*\\(/g)) console.warn('review .bind at offset ' + m.index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer arrow functions for callbacks; they need no bind.","Bind only where the body truly uses `this`.","Search for `.bind(` during review of class-to-function refactors."],"tags":["javascript","eslint","lint","functions","this-binding"],"backgroundTag":"lint-unnecessary-bind","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"}