oxc-project/oxc · error · OxcDiagnostic

Disallow recursive access to `this` within {kind}.

Error message

Disallow recursive access to `this` within {kind}.

What it means

Raised by unicorn/no-accessor-recursion when a getter or setter reads or writes the same property it defines via `this`, creating infinite recursion. The helper maps the configured accessor kind to 'get'/'set' for the message; the faulting input is the `this.prop` access inside the accessor at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_accessor_recursion.rs:19

use oxc_ast::{
    AstKind, MemberExpressionKind,
    ast::{
        BindingPattern, MethodDefinition, MethodDefinitionKind, ObjectProperty, PropertyKey,
        PropertyKind, UpdateExpression,
    },
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule};

fn no_accessor_recursion_diagnostic(span: Span, kind: &str) -> OxcDiagnostic {
    let method_kind = match kind {
        "setters" => "set",
        _ => "get",
    };
    OxcDiagnostic::warn(format!("Disallow recursive access to `this` within {kind}."))
        .with_help(format!(
            "Remove this property access, or remove `{method_kind}` from the method"
        ))
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow recursive access to `this` within getters and setters.
    ///
    /// ### Why is this bad?
    ///
    /// This rule prevents recursive access to `this` within getter and
    /// setter methods in objects and classes, avoiding infinite recursion

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Store the value in a separate private field or closure variable instead of the accessor's own property
  2. In setters, guard against self-assignment or delegate to an internal backing property
  3. Rearchitect the accessor so it does not trigger itself
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_accessor_recursion.rs:19 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/3afaa2d3c5ecd96d. Report an issue: GitHub.