{"record":{"id":"5381036b05b9ed75","repo":"oxc-project/oxc","slug":"empty-object-binding-pattern","errorCode":null,"errorMessage":"Empty object binding pattern","messagePattern":"Empty object binding pattern","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty_pattern.rs","lineNumber":22,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_empty_array_pattern_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty array binding pattern\")\n        .with_help(\"Passing non-iterable values (null, undefined, numbers, booleans, etc.) will result in a runtime error because these values are not iterable.\")\n        .with_label(span)\n}\n\nfn no_empty_object_pattern_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty object binding pattern\")\n        .with_help(\"Passing `null` or `undefined` will result in runtime error because `null` and `undefined` cannot be destructured.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoEmptyPattern {\n    /// When set to `true`, this rule allows empty object patterns used directly as function\n    /// parameters, including parameters defaulted to an empty object literal.\n    allow_object_patterns_as_parameters: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow empty destructuring patterns.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty_pattern.rs#L4-L40","documentation":"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).","triggerScenarios":"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).","commonSituations":"`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.","solutions":["If you meant a default value, write `var {a = {}} = foo;` instead of `var {a: {}} = foo;`.","Destructure the fields you use, or take the whole object: `function foo(options = {}) {}`.","If the empty object parameter is an intentional API convention, enable `\"allowObjectPatternsAsParameters\": true` in the rule config.","Otherwise delete the empty pattern or suppress inline for one line."],"exampleFix":"// before\nvar {a: {}} = foo;\nfunction foo({}) {}\n\n// after\nvar {a = {}} = foo;\nfunction foo({} = {}) {} // or enable allowObjectPatternsAsParameters","handlingStrategy":"validation","validationCode":"oxlint --deny-warnings src/ # no-empty-pattern is enabled by default","typeGuard":"// if destructuring optional input, guard first\nfunction handle(opts?: Record<string, unknown>) {\n  if (opts == null) return; // avoids the TypeError the lint help warns about\n  const { a } = opts;\n}","tryCatchPattern":null,"preventionTips":["Use `= {}` for optional-options APIs instead of an empty pattern parameter.","If empty object params are your documented convention, set allowObjectPatternsAsParameters: true once in config rather than sprinkling disables.","Treat every `{}`/`[]` on the left of `=` or inside a signature as a review flag."],"tags":["eslint","destructuring","oxlint","lint","correctness"],"backgroundTag":"empty-destructuring-pattern","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}