oxc-project/oxc · error · OxcDiagnostic
Do not use an object literal as default for parameter `{para
Error message
Do not use an object literal as default for parameter `{param}`. What it means
Raised by unicorn/no-object-as-default-parameter when a function parameter's default value is an object literal (e.g. `function f(a = {})`). The identifier helper names the parameter; the faulting input is the default parameter at the labeled span.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs:12
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.View on GitHub (pinned to e1e7af627c)
Solutions
- Destructure inside the default: `function f({ a, b } = {})`
- Default each property individually: `function f(options = {}) { const a = options.a ?? defaultA }`
- Use `undefined` as the default and build the object in the body
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs:12 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/03d425890a7c3fed.
Report an issue: GitHub.