oxc-project/oxc · error · OxcDiagnostic
Do not use an object literal as default
Error message
Do not use an object literal as default
What it means
Raised by unicorn/no-object-as-default-parameter when a non-identifier parameter pattern (destructured binding or computed name) defaults to an object literal, so the parameter name cannot be reported. The faulting input is the object-literal default at the labeled span.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs:17
use oxc_ast::{
AstKind,
ast::{BindingPattern, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn identifier(span: Span, param: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Do not use an object literal as default for parameter `{param}`."))
.with_label(span)
}
fn non_identifier(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not use an object literal as default").with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoObjectAsDefaultParameter;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow the use of an object literal as a default value for a parameter.
///
/// ### Why is this bad?
///
/// Default parameters should not be passed to a function through an object literal. The `foo = {a: false}` parameter works fine if only used with one option. As soon as additional options are added, you risk replacing the whole `foo = {a: false, b: true}` object when passing only one option: `{a: true}`. For this reason, object destructuring should be used instead.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```javascriptView on GitHub (pinned to e1e7af627c)
Solutions
- Move defaults into the destructuring pattern itself
- Replace the object-literal default with `undefined` and handle defaults in the function body
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs:17 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/84fb9f6c79c9cc61.
Report an issue: GitHub.