oxc-project/oxc · warning

The function binding is unnecessary.

Error message

The function binding is unnecessary.

What it means

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.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_extra_bind.rs:15

use oxc_ast::{
    AstKind,
    ast::{Argument, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode, ast_util::is_method_call, context::LintContext, rule::Rule,
    utils::function_body_contains_this,
};

fn no_extra_bind_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("The function binding is unnecessary.")
        .with_label(span)
        .with_help("Remove the `.bind` call.")
}

#[derive(Debug, Default, Clone)]
pub struct NoExtraBind;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow unnecessary calls to `.bind()`.
    ///
    /// ### Why is this bad?
    ///
    /// This rule is aimed at avoiding the unnecessary use of `bind()`
    /// and as such will warn whenever an immediately-invoked function expression (IIFE) is using `bind()`
    /// and doesn’t have an appropriate `this` value.
    /// This rule won’t flag usage of `bind()` that includes function argument binding.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the `.bind(...)` call.
  2. Add the intended `this` reference to the body when the function should use the receiver.
  3. Replace with an arrow closure when you only needed the binding for style.
  4. Suppress once with `// oxlint-disable-next-line no-extra-bind`.

Example fix

// before
const send = function (msg) {
  return post(msg);
}.bind(socket);

// after
const send = (msg) => post(msg);
Defensive patterns

Strategy: validation

Validate before calling

// list bind sites for manual review before lint
for (const m of src.matchAll(/\.bind\s*\(/g)) console.warn('review .bind at offset ' + m.index);

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/db84b74e80adef49. Report an issue: GitHub.