oxc-project/oxc · warning · OxcDiagnostic

Empty array binding pattern

Error message

Empty array binding pattern

What it means

Diagnostic from oxlint's port of ESLint's no-empty-pattern rule (array variant). It fires on any array destructuring pattern with zero elements, e.g. `var [] = foo`. An empty pattern creates no variables yet still forces the engine to iterate the value at runtime, so non-iterables (null, undefined, numbers, booleans) throw a TypeError. It is almost always a typo where the author meant a default value or deleted the bound names.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_empty_pattern.rs:16

use schemars::JsonSchema;
use serde::Deserialize;

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

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

fn no_empty_array_pattern_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Empty array binding pattern")
        .with_help("Passing non-iterable values (null, undefined, numbers, booleans, etc.) will result in a runtime error because these values are not iterable.")
        .with_label(span)
}

fn no_empty_object_pattern_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Empty object binding pattern")
        .with_help("Passing `null` or `undefined` will result in runtime error because `null` and `undefined` cannot be destructured.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoEmptyPattern {
    /// When set to `true`, this rule allows empty object patterns used directly as function
    /// parameters, including parameters defaulted to an empty object literal.
    allow_object_patterns_as_parameters: bool,
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. If you meant a default value, move the brackets to the initializer: `var {a = []} = foo;`
  2. If no binding is needed, delete the empty pattern entirely.
  3. For parameters, destructure the fields you actually use, or accept the whole value: `function foo(options) {}`.
  4. If it is provably intentional, suppress once with an `oxlint-disable no-empty-pattern` comment (no config option exists for the array form).

Example fix

// before
var {a: []} = foo;
function foo([]) {}

// after
var {a = []} = foo;
function foo(a = []) {}
Defensive patterns

Strategy: validation

Validate before calling

# CI gate: fail on the diagnostic before it reaches users
oxlint --deny-warnings --rule 'no-empty-pattern=warn' src/

Type guard

// optional runtime guard if you must destructure unknown input
const isIterable = (v: unknown): v is Iterable<unknown> =>
  v != null && typeof (v as Iterable<unknown>)[Symbol.iterator] === 'function';

Prevention

When it happens

Trigger: Any zero-element ArrayPattern anywhere in the AST: `var [] = foo;`, `const {a: []} = foo;` (nested), `function foo([]) {}` (parameter), per the `AstKind::ArrayPattern if array.is_empty()` check. Unlike the object variant, no option suppresses the array form.

Common situations: Intended a default (`var {a = []} = foo`) but wrote the pattern form (`var {a: []} = foo`); names removed during refactoring leaving `[]` behind; empty destructured parameters used as 'takes an array' documentation; auto-generated code emitting empty patterns.

Related errors


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