oxc-project/oxc · warning · OxcDiagnostic

Empty object binding pattern

Error message

Empty object binding pattern

What it means

Object variant of oxlint's no-empty-pattern rule. Fires on `{}` object patterns that bind nothing: `var {} = foo`, `const {a: {}} = foo`, `function foo({}) {}`. At runtime the destructuring still performs a ToObject/property access, so passing null or undefined throws a TypeError. The rule exposes `allowObjectPatternsAsParameters` to permit empty object patterns used directly as function parameters (including ones defaulted to an empty object literal).

Source

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

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,
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow empty destructuring patterns.
    ///
    /// ### Why is this bad?

View on GitHub (pinned to e1e7af627c)

Solutions

  1. If you meant a default value, write `var {a = {}} = foo;` instead of `var {a: {}} = foo;`.
  2. Destructure the fields you use, or take the whole object: `function foo(options = {}) {}`.
  3. If the empty object parameter is an intentional API convention, enable `"allowObjectPatternsAsParameters": true` in the rule config.
  4. Otherwise delete the empty pattern or suppress inline for one line.

Example fix

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

// after
var {a = {}} = foo;
function foo({} = {}) {} // or enable allowObjectPatternsAsParameters
Defensive patterns

Strategy: validation

Validate before calling

oxlint --deny-warnings src/ # no-empty-pattern is enabled by default

Type guard

// if destructuring optional input, guard first
function handle(opts?: Record<string, unknown>) {
  if (opts == null) return; // avoids the TypeError the lint help warns about
  const { a } = opts;
}

Prevention

When it happens

Trigger: Any zero-property ObjectPattern, per the `AstKind::ObjectPattern if object.is_empty()` check, unless allowObjectPatternsAsParameters is true AND the pattern is a FormalParameter whose initializer is absent or an empty object literal (`function foo({}) {}`, `function foo({} = {}) {}` are then allowed; `function foo({} = value) {}` or nested `{a: {}}` still report).

Common situations: `var {a: {}} = foo` written instead of the default `var {a = {}} = foo` (the visually similar, subtler mistake the docs call out); empty destructured options parameter `function render({}) {}`; refactors that removed the last destructured field; copy-paste from docs using the pattern as a placeholder.

Related errors


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