oxc-project/oxc · error · OxcDiagnostic

Avoid using 'thisArg' with array iteration methods

Error message

Avoid using 'thisArg' with array iteration methods

What it means

Raised by unicorn/no-array-method-this-argument when an array iteration method (map/filter/etc., or Array.from) is passed a `thisArg` second/third argument. The checkers (check_array_prototype_methods, check_array_from) flag the extra binding argument; the faulting input is the thisArg argument at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_array_method_this_argument.rs:15

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

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

fn no_array_method_this_argument_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Avoid using 'thisArg' with array iteration methods")
        .with_help("Use arrow functions or lexical scoping instead of passing 'thisArg' as a second argument to array methods like map, filter, etc.")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows the use of the `thisArg` parameter in array iteration methods such as
    /// `map`, `filter`, `some`, `every`, and similar.
    ///
    /// ### Why is this bad?
    ///
    /// The `thisArg` parameter makes code harder to understand and reason about. Instead,
    /// prefer arrow functions or bind explicitly in a clearer way. Arrow functions inherit
    /// `this` from the lexical scope, which is more intuitive and less error-prone.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the thisArg and capture `this` lexically inside an arrow function callback
  2. Bind the function once outside the iteration and use the bound reference
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_array_method_this_argument.rs:15 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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